We will hold AtCoder Beginner Contest 390.
- Contest URL: https://atcoder.jp/contests/abc390
- Start Time: http://www.timeanddate.com/worldclock/fixedtime.html?iso=20250125T2100&p1=248
- Duration: 100 minutes
- Writer: math957963, sounansya
- Tester: Nyaan, yuto1115
- Rated range: ~ 1999
- The point values: 150-200-300-400-450-525-600
We are looking forward to your participation!








I look forward to every weekend for atcoder contests
me too
Planned post contest discussion
Update: VOD Twitch YouTube
stop this it's annoying enough
Thanks for watching :)
I am very weak in algorithms. What can I do?
At: https://atcoder.jp/users/da_ke
Remember here is another juruo (it has a same sound as "very weak" in Chinese)is weaker than you.
QAQ
You are all dalaos.
I'm a juruo, too.
I only solve ABC in this contest. qwq.
How to improve?
Just practice more. In one word, correct the problems which u didnt solved in the contest. u'll gain a lot from this <3
Good luck!
Downvoted.
The problem D is the shitest problem I have seen.
Over 150 people passed only A,B,C,E,F but can't pass D.(including me)
So, how is it done, did not solve it?
E was simpler.
So, it is kind of a clever brute force :/
link to editorial
Mine was not clever enough, but basically the right aproach.
What? I solved D by just doing brute force with recursion. I don't get how it has fewer solves than E tbh.
How did you solve D, your approach?
Here is the code of the recursive function. Basically, I just do it as: Try to add the current number (
a[idx]) for each index of the vectorsums(Basically making a copy ofsumswith the element increased), or just add it to the end ofsums. When reaching the end, just take the xor and save it to a set.(Also as a side note, you can speed this up significantly by not using an
unordered_set, but instead just use avector, then usesortanduniqueon the vector to get the same result).My dfs got TLE.
Agree! I used 1 hour to solve D and don't have time to solve F! (I can solve it in at most 40min)
D is totally SHIT.
How to do D?
is E Binary Search + Dp??
No need to binary search. It can be solved with simple knapsack.
damn, i missed it xD
DP then triple pointer?
Just brute force the partition of X into 3 parts in X^2
Oh, good idea! thx.
Note that each food contains only one vitamin. So there are 3 groups of food. Foreach food we can dp the max amt of vitamin per calorie intake.
Then one can binary search a min vit intake, by finding the min index in the dp with that min vit intake as the sum of the 3 groups.
only a simple knapsack
Can anyone tell me what was wrong with my solution for Problem B, where the task was to determine whether the sequence is a progression or not? I tried to find all the ratios, store them in a map, and check if there were any other ratios by verifying the size of the map. Why did this solution fail in one test case? It would be very helpful if someone could explain the root cause of the failure
try long double
Enough of coin-toss problems like D.
At least for me Problem D is related to Stirling numbers. I saw some ways to count partitions using stirling numbers, the next partition always need to have the first unused number in previous partitions. The total number of ways is the sum {n, 1}, {n, 2} ... {n, n}.
I work very slowly on question B, but most of the time I search for 'geometric progress' on Google. I think it should be briefly described in the question
Took a lot of time to solve ABC, solved E just after the contest ended :(
E was a good binary search + DP problem. How to solve D?
Good contest, thanks for the round math957963 sounansya and all testers!
Problems on recursion always look for me like "do the exact implementation, as author did".
Can someone explain solution for F. Cannot understand the editorial
Consider the contribution of each element
a[i]. If there are multiple instances ofa[i]in an interval, only the first instance contributes.Case 1: The contribution is +1 for every interval, which has neither of the values
a[i], a[i]-1, a[i]+1at positions beforei.Case 2: You also need to consider the negative contribution (-1), where
a[i]merges two ranges. This will be the case for all intervals, wherea[i]-1anda[i]+1exist, but nota[i](at positions beforei)how do you handle 2nd case here? Can you post your submission link pls?
See below
Got it, Thanks!
If a[i]-1 and a[i]+1 exist and a[i] doesn't exist, then, p0!=-1 and p2!=-1 and p1==-1. Then, wrapping the line
in an if check, like this ..
yields WA. Any idea why ?
I can't understand 3rd test case of problem D
Test Case — 3 :
6
71 74 45 34 31 60
Result :
84
How ? Explain anyone please!
In problem E, if each food contains all 3 vitamins and the input is like this: Ai1, Ai2, Ai3, Ci (where Aij is Aij units of jth vitamin) Then how do we solve the same problem?
Can someone explain approach for problem D? I didn't understand the editorial.
During the contest, I have a WONDERFUL solution for Problem D (I think the Problem E is harder than Problem D).
Seeing that $$$N$$$ is so small, it's not hard to think of a search implementation, so you can write a simple search: DFS to the $$$x$$$-th point, and then enumerate $$$i\in [1,N]$$$ to indicate that $$$A_x$$$ moved to $$$B_i$$$, when $$$x \gt N$$$ time to calculate the value of XOR, and use the
unordered_mapstatistical answer can be. This has a time complexity of $$$O(N\times N^N)$$$, but in practice, because of the constant problem, only the testcases of $$$N\le 8$$$ can be passed in the time limit of $$$3\text{s}$$$.Consider pruning (the official solution uses
set, I don't know how to do QWQ), first of all, the enumeration range can be adjusted to $$$i\in [1,x]$$$, because the front moves to the back and the back moves to the front are the same, so the time complexity is reduced to $$$O(N\times N!)$$$, and can pass the testcases of $$$N\le 11$$$. Consider to continue optimization, found that when $$$B_j=0$$$ when the $$$A_i$$$ to $$$B_j$$$ operation is meaningless (just changed the position), so the transfer can be special judgment, so that can be used $$$1.5\text{s}$$$ perfect through this problem. The time complexity is $$$O(NB(N))$$$, where $$$B(N)$$$ denotes the Bell Number of $$$N$$$, and the maximum is $$$4213597$$$, which is sufficient to pass the question.My Code.
The time complexity isn't $$$O(N!)$$$ here; your solution is precisely the intended solution mentioned in the editorial.