Hello, Codeforces!
auiunu, NahC0el and me are glad to invite you to the last round with 10 binary bits — Codeforces Round 1023 (Div. 2), which will start on May/05/2025 17:35 (Moscow time). You will be given 6 problems and 1 subtask with 2 hours 15 minutes to solve them.
The round will be rated for participants of Division 2 with a rating lower than 2100. Division 1 participants can participate unofficially.
All problems are authored by auiunu, NahC0el and me.
We would like to thank:
- Dominater069 and TheScrasse for their wonderful coordination and huge help in preparing the round.
- Alexdat2000 for the Russian translations.
- hyman00, le0n, Flamire, jeroenodb for LGM testing.
- Sana, N_z__, Wuyanru, Little_Bunny, platter, yeminghan, MridulAhi, xuyifei1, Error_Yuan, nifeshe, wfb, _istil for red testing.
- Intellegent, Proof_by_QED, TyroWhizz, Coffee_zzz, yoru_sacri, Edeeva, Caylex, satyam343, luuia for yellow testing.
- rewhile,unforgettablepl, Friedrich for purple testing.
- SpyrosAliv, beaten_by_ai, yashbihany, oviyan_gandhi, hyhcnzjsx, starrykiller, mathtsai, macaquedev, AG-88301, avighnakc, SkyWave2022, chromate00 for blue testing.
- STAR_light_ for black testing.
- MikeMirzayanov for the great Codeforces and Polygon platforms.
- You for participating.
The score distribution is $$$250-750-1500-2000-2750-(2250-2500)$$$.
We hope you will enjoy and have fun in the contest. Good luck!

UPD: Congratulations to the winners and first solves!
Div. 1+2:
Div. 2:
First solves:
- Problem A: Hamed_Ghaffari at 00:01.
- Problem B: arvindf232 at 00:03.
- Problem C: arvindf232 at 00:08.
- Problem D: Wansur at 00:22.
- Problem E: SSerxhs at 00:29.
- Problem F1: peti1234 at 00:14.
- Problem F2: conqueror_of_tourist at 00:33.
UPD2: Editorial is out!








As a tester, Dominater069 orz.
As A participant I hope Enjoy.
And I hope for a non-negative Delta!
We hope lol .
hope to solve ABCD in 90 mins :)
What happened to the contest which was gonna take place tomorrow?
OMG round $$$(1111111111)_2$$$ as a tester!
Fun fact
Fun fact: The previous contest that had 250 points on A was Global Round 28, which was on December 2024
that means that A will be easy compared to last 2-3 contests?
As a tester, I tested
As a tester, I loved the problems
250 for A and 1500 for C.
Feels like a trap.
ok.. surprising that the first problem has a score of 250 .... what does this mean?
This indicates an Ad-hoc / Cake-walk / Easy problem A (the first one).
ok, thank you
People should consider solving C earlier in this round.
Explanation: If somebody can solve A in 10 min, B in 20min, and C in 40 min; The solving order A,B,C gives (250-10)+(500-60)+(1500-420)=1760 round score. On the other hand, C,B,A gives (1500-160)+(500-120)+(250-70)=2000 round score. But, if you aren't able to solve C, this would work negatively.
Don’t give them ideas bro I don’t wanna start solving from C…
in this case A, B, C ordering will be better
Seems the problem of solve which first can be solved by greedy.I should first the problem with high division of score and time. (score/time)
Oh your calculation seems wrong.The grades are both 1900
One of the tester is banned now lol
To save your time, it's luuia
finally , i'll become newbie
The only benefit of starting from div3/div4 is your ratings grow faster, but not higher. I think experience one more round is better.
With this score distribution problem A is going to be cout << a+b << endl;
luuia's testing hopefully means the round is GPT proof
Yeah I'm out of competition now
So Imma prepare a template for odd-even and sum of two no.s for A.:)
RGB contest
Red sunkuangzheng
Green auiunu
Blue NahC0el
I hope the first problem is not just "print 2^10-1"
Assuming ^ is xor, that would be 7
He meant $$$2^{10}-1=1023$$$ i.e. count of the round
11, actually
I hope to not get minus on A
I Wish to solve D; else will get cooked..
how does this tool work... what does skipped contest mean in this tool ?
that mean he cheated in that round
I know there will be an unordered_map solution which will get hacked, which makes rewhile happy.
I know it from past experience 287756206
oh I don't know about this. how to save ourself from this hack ?
See this blog
oh wow, thanks so much
As a tester, have fun and good luck!
yashbihany orz!
why is hyman00 so strong?
As a participant, I hope a non-negative delta.
how many problems do i need to solve to reach pupil in this round.Also how much time should i invest
A and B are enough, but your goal should be to solve as much as you can.
What a hard contest!
CASE_WORK_forces and WRONG_ANSWER_forces on C for me... One day I will properly test my code before submission.
I have some comments in my code but it is not AI generate I promise.
Me with 5 WAs on B, such a good day...
salute sir !!! LOL
I also made one wrong in B .. I didn't check if there can be more than one occurrence of maximum value .. yikes :(
Also did the same mistake lol!
I bricked on B too. I really dislike this problem... It doesn't even fit as a div2B imo, its difficulty is below A and only had a lower solve count because many people didn't see the "edge case" of multiple maximums (just my guess though). Left me so tilted I ended up bricking C too
Is there any solution for D that don't require centroid, I don't want to implement centroid so I am very curious.
There is, I chose to find a diameter path and from there, remove all nodes in the path, which isn't explicityly centroid, but it is similar.
Does D solution use a tree structure with heap? What an interesting problem!
I solved D just by iterating to find the tree diameter :D
Can someone prove that this algorithm doesn't TLE? It runs in about 1.5 seconds.
I was thinking same. but, what to do after first diameter? no, clues!
I perform DFS twice to find the tree's diameter, then mark the removed nodes, and repeat the process.
If you cut diameter D at some iteration, next iteration your diameter will be at most D-1.
Proof by contradiction — if in two iterations you cut two diameters of the same length D in a tree, then there must be an edge between them (since graph is connected), and then your first diameter is larger than D.
If you remove D nodes at one iteration, then D-1, then D-2, ..., then the total number of nodes you remove O(D^2), and you do it in O(D) iterations. So at most you will have O(sqrt(n)) iterations, and total complexity is O(n*sqrt(n)).
Maybe there is even better bound, let's see in editorial
I made an assumption that breaking the diameter away will always make tree less than half in size .. so that my solution will not become O(n^2) .. but I don't know the proof for this.
if this is wrong I guess I might get TLE in system tests.
Same bro, we will see soon
yeah. fingers crossed... I tried to google something like
centroid decompition == diameter decomposition.. but couldn't find anything ... but on paper my solution was giving right answer after removing the diameter, so I made a submissionIt can be proven that every element will remain at most logn times. If you stretch the tree along its diameters, you can see that after deleting the diamater, the remaining subtree will have height of at most n/2.
oh wow, thanks
I was not able to make that observation during the contest.
I have seen SecondThread's lesson on trees, on which he explains exactly this concept.
oh ok, thanks for telling me.. I think I should also watch it.
Yeah, There was also other cool techniques and concepts.
ok, I will watch it soon.
Elements may remain more than O(log(n)) times, since even if the height of a subtree is bounded by n/2, diameter of the subtree doesn't have such bound.
\
I wish next time I could know more than I am cooked when I see the Time constraint is 5s for Problem D.
please tell me there is a simple trick to solve C .. I spent so much time ...
I was able to solve D faster ( although my D can fail system tests )
Mark all 0s as -inf. Then pick one of them. Let m1 be largest sum [i....j — 1] such that j = k (where k is the index of 0 we are working on) and m2 be largest sum [j + 1 ..... i]. Let m1 and m2 >= 0, then a[j] = k — m1 — m2. Just do a quick check with subarray sums at the end.
ok I understand. I think this makes sense and I can see how this can avoid some of my case work. I did something similar but with a lot of case work before this.
thanks
I did same can you tell me where i went wrong mySubmission
this is wrong. in the sample
an answer is possible by doing
Use prefix_max and suffix_max by centering any of '0'.
nice d2. solved A and C with tons of penalties :(
How to solve B?
so if condition 3 was not there .. then it is easy ... sum all numbers and
number of moves = sumso we can just check if it is even or odddbut condition 3 can only work in First move.. if it doesn't apply in first move .. then observe that you can never increase the value of
max-minso we just need to check if in first move it is possible to reach a state where
max-min <= kthen game continues and we can have that odd-even checkCan you help me find the issue in this? Link
Thank you.... (I understood the logic)
My code gives "Jerry" .. yours give "Tom"
This condition is wrong : mx — mn > k + 1, think for a case where you have more than 1 mx occurrence in array.
In "C," there is no mention that the sum must be greater than -1e18.[updated]
The sum must be $$$k$$$, which is $$$\leq 10^{12}$$$
If you have any segment with a sum of more than $$$k$$$ (which is at most $$$10^{12}$$$) that is wrong answer for sure.
Actually, i was replace all unfixed '0' to 1e18, except one '0'. that's give wa on 4.After replace 1e18 with 1e13 got "AC".
I guess you mean $$$-10^{13}$$$, right? Because using any value larger than $$$k$$$ is 100% wrong answer. I used $$$-10^{18}$$$ and it passed all the tests.
Why does finding diameter trivial solution still pass time limit for this test???
Time limit 5s is so sus in the first place
because after 1 operation you have erased all nodes :fire:
I think worst case is binary tree for D
Damn, I forgot that after erase the diameter you also erase node 1.
It all depends on your implementation. You first cut the path from n to n — 1. Now you are left with all single nodes.
Calculating the diameter should take $$$O(n)$$$ time where $$$n$$$ is the size of the tree. First you calculate it for the entire tree taking $$$O(n)$$$ time. Now when you remove that path, you are left with $$$n-3$$$ trees which each contain a single vertex. So you calculate the diameter for each of those trees, each in $$$O(1)$$$ time for a total of $$$O(n)$$$ time once more. Now each tree is just a single path so you keep removing them and don't have to calculate any diameter.
I am Cooked.I wasn't able to solve neither A nor B. Urgently Need to practice
What is wrong in my code for B it is giving WA5
Did you check if 2 piles have min + k + 1?
use long long
I am using #int long long in original code
in line
int tot = accumulate(v.begin() , v.end() , 0);put
0LLinstead of0i think thats the problemMy solution for D:
For the original tree, we find an optimal diameter and remove it from the tree. Afterward, the tree is split into several connected components, and we recursively solve the problem for each component. This process is somewhat similar to the centroid decomposition of a tree. However, I believe it is essentially a "center decomposition" of the tree.
How to compute the time complexity? We only need to consider the following problem: Given a tree T, define $$$f(T)$$$ as $$$max(f(comp[i])) + 1$$$, where $$$comp[i]$$$ are the connected components obtained by removing the diameter of $$$T$$$. An important observation is that removing the diameter of $$$T$$$ will inevitably delete the center of $$$T$$$, which ensures that the diameter of $$$comp[i]$$$ must be smaller than that of $$$T$$$. From this, we can deduce that $$$f(T)$$$ is $$$O(\sqrt(n))$$$ (for a tree $$$T$$$ satisfying $$$f(T) = i$$$, the diameter of $$$T$$$ must be $$$\ge i$$$).
I believe my implementation is $$$O(n \sqrt(n) log n)$$$, and fortunately, it passed. Unfortunately, I submitted it incorrectly multiple times.
AC code:318524754
I made same assumption about time complexity .. fingers crossed LOL
E is very cool, I like it very much! F is cool too
how did you guys do c?
binary search
how, please explain ?
Set all but 1 changeable positions(s[i]=0) to -1e16. Then do binary seach on that position and use Kadane's algorithm to check.
Take a look at my submission to see an implementation https://codeforces.me/contest/2107/submission/318500812
thanks bro
but how did you find out that the binary search will work for any index where s[i]=0 ?
It has to.
Assume it didn't, and no matter what value I put in the spot, the value is above k, then that what would mean that there is a subarray in the nonchangeable part that has a value greater than k, I am already cooked at that point, so you that first check that case by turning everything into negative infinity then if it is below k, then it is possible else it isn't.
You don't need binary search. Let x be the largest subarray to the left, and y be the largest subarray to the right. You can set a[i] to k — x — y.
I have biggest oversight of my life is thinking a[i] always should be set >= 0... actually false assumption.
Yes the answer is a[i] = k-x-y, and it can be negative.
After the recent rounds Codeforces team showed that they don't care about cheaters and will not ban even super obvious ones, cheaters stopped even pretending they are not. Look at this clown's submissions: idk404, submitted multiple different codes for problem E in just few minutes, two of them are accepted. Some problems are solved in C++, some are solved in Python, but the variable names are so descriptive, surely a pro.
The round author is a cheater... What do you expect?
Which one?
sunkuangzheng, the author of this announcement blog.
https://codeforces.me/blog/entry/142548?#comment-1272714
Yep, thanks, looks like a 100% cheater. Seems that CF stands for CheaterForces nowadays. No steps are done to make cheating less simple, super arrogant cheaters stand at the top of the standings, but some cheaters are allowed to conduct rounds. Amazing job, Codeforces team!
All cheaters must die
Look at the submission of this guy Yuvi0311 for problem D, it is similar to submission of this guy idk404. He has only changed the variables name, rest code is exactly same.
I request contest organizer to take strict action against these type of activities.
dude wtf, I did it on my own. idk about the other guy. Are you so unemployed that you're reading random codes
You did it by yourself and still this is the outcome.
In my opinion, you should be permanently banned from Codeforces.
Solved A,B,C within 40 min, was not able to solve D, was thinking something similar to finding diameter, but unfortunately wasn't able to implement it.
is there easy technique to find lexicographically largest diameter ? I did 3 traversals to achieve it .. feels not very clean.
hoping to get some code pointers from editorial.
I did it using dp on trees. I rooted the tree at node 1, and for each node v I stored dp[v] = the maximum value of the pair (length of path, other end of the path), over all paths whose highest point is v. The transitions are pretty straightforward. For the final answer I just iterated over every node and looked at two highest dp values among its children and merged those two paths.
oh ok, thanks... I think I need to brush up on dp on trees
Once a path is selected whose highest point is $$$v$$$. DP values for all the parents of $$$v$$$ needs to be updated. Did you update those values as well?
The number of parents whose dp values need to be updated $$$\leq d$$$. So, total number of parents that need to be updated $$$\leq n$$$ over the number of paths in the answer.
I'm not updating anything. I have just shared my approach to calculate the lexicographically maximum possible diameter in O(n). When I'm deleting a diameter I'm again taking O(n) time to update for the new subtrees.
why this code fails for problem $$$F1$$$ ?
What is the upper bound for time complexity for problem D?
I guess $$$O(N\sqrt{N}))$$$, because on every step you take path with length greater than $$$\sqrt{N}$$$, or if there is no such path, that means that tree has height less than $$$O(\sqrt {N})$$$, so you decrease height of the tree by 1. One can see that there are $$$O(\sqrt{N})$$$ such steps
I think it's $$$O(n \log n)$$$, since each time the diameter is halved.
Not necessarily, for a tree like this:
The diameter of the tree rooted in node 4, after taking off the bold nodes, will be 6, just two less than the original.
Can some one help me what i did wrong in this submission, My Submission.
This is the submission for problem C, but I am getting out of bound error on string s, what have i missed?
You have an overflow when inputting k. That's causing undefined behavior in cin.
Thanks a lot.
why am i unofficial!!! I dont see myself on the common standings unless I click show unofficial. I registered as official and I think I am a trusted participant.
Where is the editorial?
Great problems, thanks
Writing From Hell because i died while debugging my own code and still not able to get where i am wrong:318542988
My approach:
1.Taking all segments where s[i]='1',and then finding max subarray sum of those segments, and storing max of all such maximum subarray sum of those segments say mx. If (mx ==k) then i set all a[i]=-1e18 such that s[i]='0' if (mx>k) then answer doesnt exist
Then returned the array.Please reply fast i am about to get deep fried here.
in your second loop try to keep s[j]=='0' instead of s[j]=='1' and lastright should be i+1 and last left should be i-1
318546694 Yes that was a silly mistake but it is still wrong
is it working now?
WA
here is ur correct sol https://codeforces.me/contest/2107/submission/318547725
what could be the reason for a memory limit exceeded in general
You use too much memory (possible a memory leak)
Congratulations to MOAQ_150 for getting top 100 trusted participant, despite being unable to solve A by himself: 318512987
They also seem to have the extraordinary talent of converting 100+ lines of Python code to 200+ lines of C++ code in under two minutes! And these comments are so beautiful!
I guess he was afraid of being banned because of the rule against code obfuscation and decided to document everything last minute
Strange, is something wrong with CF? Look at this user uk_024
This user is a cheater, and its E submission was skipped after rating calculation. Wait for rating rollback.
Hello, I received a plagiarism warning for problem 2107A due to a match between solutions from emper0r_24 and dragon_emper0r. I would like to clarify that both accounts belong to me. I started giving contests using this(dragon_emper0r) account. But I mistakenly submitted the solution to A using the old id(emper0r_24). I did not intend to violate the rules. I apologize for the confusion and assure that it won't happen again. I’ll stick to one account from now on.
Thank you for your understanding.
There could have been two variants of the problem C.
Variant one : we can replace a[i] with any values till -10 ^ 18 to 10 ^ 18.
Variant two : we can replace a[i] with less than value till -10 ^ 6 to 10 ^ 6.
Does variant two make the question more difficult ?
sunkuangzheng ?
.
You use #define ll long long in C but not for B? You also use camelcase style for both A and B but not for C. Suspicious imo.
Dear Codeforces team,
I received a notification that my solution (ID: 318491650) for problem 2107C is similar to other submissions. I would like to clarify that I wrote my solution independently and did not share my code with anyone, nor did I copy from others.
I wrote the code locally on my personal computer using IntelliJ IDEA and did not use any online compilers, public repositories, or code-sharing platforms during the contest. I also did not discuss or share my solution with anyone.
Please let me know if there’s any further information I can provide to clarify this situation. Thank you for your time and understanding.
Your question submission has been cancelled, why do you still enjoy the rating ?
Apparently this “rollback” operation has not been automated, as it does not make sense otherwise why it’s so infrequent.
unforgettablepl congrats darling :D
Thank you darling :D
Good luck to conqueror_of_tourist on his mission