こんにちは, Codeforces!
Since our first round, we've learned a lot, and now we're excited to invite you to participate in Codeforces Round 1022 (Div. 2), which will be held at May/01/2025 17:35 (Moscow time). The round will feature 6 OR 7 full Leetcode implementation problems, where OR means the bitwise "we don't know" operation, and you'll have 2 hours to solve them. Some of the problems might be interactive — you can read more about interactive problems here.
The round will be rated for all participants with a rating below 2100, but everyone is welcome to participate out of competition as well.
All problems were authored and prepared by m3tr0, suprend, and me.
We would like to express our huge thanks to Akulyat for the fantastic coordination of the round and playing $$$\text{Tower Defense}$$$, as well as to all our testers:
- A_G for red-black-tree style testing.
- NemanjaSo2005, sammyuri, and N_z__ for bloody testing.
- Proof_by_QED, mwen, and KiKoS for sparagmos testing.
- xelsink1 and Hausdorf for gangway testing.
- ko0g, larush, and Ratery for heavenly testing.
- ne_justlm, Plotva, and Sobaka_ulybaka for testing the color of the flying stone.
- chepvl for testing the color of the spanning tree.
And, of course, huge thanks to MikeMirzayanov for the すばらしい Codeforces and Polygon platforms, and You for participating!
UPD1: Score distribution: $$$500-1250-1500-2250-2750-3250$$$
UPD2: Congratulations to all the fighters of trees and towers! The final mousing:
All participants:
Moused only:
UPD3: Editorial is here!








Isn't this quite late for the announcement to come out
what's the score distribution?
we still don't know ourselves( I'll drop it as soon as possible
i have engineering graphic exam the next day of this round but i am from a warrior race
As a spectator excited to see how many of our talented newbies AK the contest
As we know, many newbies are talented in using LLMs.
It is well known that many newbies are talented in the use of LLMs.(As a steady newbie, it's clear that I'm not one of them)
hope to become CM
But Im in competition !
Niceeeee, you'll solve it all, right?
It's supposed to be master not candidate master
The subarashi in Japanese takes you to a random subarashi video. crazy man
But it's cool :)
May the force be with you to rock on..
..labour's day.
All the best everybody :)
what about scores?
As a participant, I hope to solve two or three problems in this contest.
I hope it is not a speed round.
Hope to be Pupil!
Hoping for colour change delta
6 OR 7 problems, where OR means the bitwise "we don't know" operation
Should I be scared?
I'll get orange now
i hope you get. good luck.
GUYS THEY DID!! Huge congrats
Subarashiiiiii!!!! (¬‿¬)(¬‿¬)(¬‿¬)
Happy May Day!
The OR in the announcement is the bitwise AND operation
As a participant, there will be a lot of blogs about cheaters right after the contest.
It's great to see so many people taking it upon themselves to maintain the codeforces community environment.
just like after every contest lol, but actually it seems like gpt is very bad with solving them
I am so unlucky that I commented there was going to be a ton of blogs about cheating (like literally every contest in the past two months) and there was none. Maybe I should comment this under every contest I participate to avoid cheaters. If I was born 2000 years ago I would’ve bet my life saving on Golias for 1.1 odd ;(
Look at this blog
hoping for the first time in top 4k in div2 !
Scores? A: 500 B: 1250 -_- Used to seeing A 750 and B 1k guess now that’s the new norm.
Cherry_blossom_ this person used ai in the last educational round and most probably is using ai now
hhh, I have used too many time on problem B. It is a good problem!
me reading problem A .. is this div1 A
me reading problem B .. is this div1 B
I had 30+ seconds remaining, yet the submit button was not clicking. Too bad codeforces.
When is editorial coming out
What's up with these shitty difficulty distributions lately? D is way too hard for its position.
My solution just barely fit in the time limit, I basically just used binary search but we'll see if that is correct and fast enough
I think main observation was window of size K will repeat in both A and B but I was not able to completely solve it :(
I tried binary searching where the pattern breaks but couldn't handle all cases.
I generated a vector of all possible indices i within [k, n-k+1] where a[i] and b[i] differ. a[i] assuming a is max length (n-k), and b[i] assuming b is max length (n-k).
Then I did binsearch on that vector. If the middle ends up being one or more indices where a[i] = b[i], then -1.
oh cool.. I tried to binary search on the first element which was not matching ... I guess your solution is better but not sure if it will overflow the number of queries
I did this calculation ... logN ~= 20 and I can't make 20 * k ( ie 20 * 50 ) queries
but generally protests have one such case which breaks the time limit.. so it can go through.. best wishes
constructing a and b is k queries each (so at most 100). then binsearch on n (1e6) is at most 20, so should comfortably be enough queries.
the bigger problem is that my solution passed pretest in 2.937s, time limit is 3s so we'll see
edit: passed :D
ok cool .. i wish you the best
D felt quite normal difficulty to me, I solved it pretty quickly
Cuz you are a master, look at the solved counts.
I was comparing to other D2 rounds. The solved counts are probably so low because most people got stuck on B and C and didn't look at D
Hi, may someone please explain me D or give me a hint on why I might get TLE?
My submission is: 318015724
you can't use unordered_map in codeforces (https://mirror.codeforces.com/blog/entry/62393)
At first sight: C<D
In fact: C<<<<<<D
I felt like it was < or << lol
For me C<<<<B. But I never like XOR tasks
I like XOR tasks but I would still say B > C
Your explaining pictures are excellent! I like it very much! How did you make it?
If only all contests had such clear explanations for the samples… the world would be a brighter, better place
You know what? I would rather call it art.
Oh, thank you!) I drew them via MS Excel
You mean just by merging/recoloring cells in tables?? It's madness, but it's absolutely incredible
yeah. I think it's easier for "rectangular" data than in some graphical editor)
B,C=C,B
No because C<B
for the question 2 :
how the answer is 8 or 5 0 can someone elaborate ??
because for length 5 the minimum sum can be 4 1 1 1 1 0
in the question it says "construct an array of positive numbers"
you can't use 0, it must be positive
Worst round I have joined yet
Why? A problem seems to be some observation or trick, I couldn’t get. But overall A, B, C, seemed as always, no?
Wayy too many adhoc.. For A you just have to kinda guess it, for B you just have to if else and if else. I guess C is alright but then it doesnt use any classical techniques so really it should be at B .. Then it is immediately followed by D which is diabolical
personally, I felt like the difficulty order was A > B > C.
A: 1 + (maximum possible sum) /2 ... However, I don't have a formal proof for this.
B: lots of casework and handling them gracefully
C: simple observation => calculate total no of local maxima
casework in B makes it much tougher compared to C, C is just simple observation and sets
What is the question of B, inexplicable!!!!
It's too many conditions and too many if-elses.Need to carefully think of what if n is 1,2,other;and what if x is 0,1,other.
Here's my code.https://mirror.codeforces.com/contest/2108/submission/317970208
am i dumb or was c more doable than b?
Did the authors mistakenly perform B^=C, C^=B, B^=C?
That was good !!
Can anyone please help me with this code for problem C. It passed the first pretest but was failing again and again in second pretest. Any help would be appreciated.
not reading the code but can you try these cases
9 2 8 8 9and9 8 8 2 9both should give same answer which is
2I am sorry if I am wrong.. but my pretest 2 failed in this was the case I found
thnx bro,its second time u helped me.
i also got the same case wrong
no problem.
are you aware that using generative AI is against the rules
whoa .. I didn't notice.. nice catch.. so many comments.
Yes, and I haven’t used it. I write comments for my own understanding.
then why do you delete your comments before submitting?
I typed them after submitting, that’s why Becuase if I write during submit then it would cost time. So I write comments after submitting my code explaining my approach to myself.
To be quite fair, his profile combined with the somewhat uneven nature of his comments do make it seem quite possible that he wrote his comments himself
This guy is blatantly cheating in all of the other contests too!
how to solve D, E ?
D seems like binary search problem. I may be wrong.
it is .. 250 is much smaller than square root so it gave a hint of binary search
yes, I used binary search to solve it
The gap between C and D is too big!
I spend on A,B,C for only 30 min, but it took an hour and a half on solving D, and there was still no gain from D.
Is this a penalty sitting?
My English is really bad, please forgive me.
seems that there’s no penalty if you didn’t get accepted
took too long to realize A. and got cooked on B.
I hope the System tests accounts for O(n) sols in D.
does O(n) pass the pretests ?
In problem D, does there exist a test case that we can find the lengths of arrays A and B in more than 250 queries?
Yes
what .. how ?
If the task can be solved by knowing the entire array C, then it is solvable within 250 queries.
OK thanks.
If the answer can be found in any number of queries, it can be found in $$$250$$$ queries
Where is the editorial?
why not swap pB & pC, and it's the worst pB I experienced.
Problem E
This too.
No wonder GPT could solve it, it could just search the problem editorial
In my humble opinion, B was really not fun. I couldn't find a better approach than to enumerate edge cases, which isn't much interesting imo.
it was a good problem but should be C I think .. I agree that it was not fun ha ha :(
who spent time actually figuring out problem A.. I just guessed it will always be even :( very sad.
The same for me. I just noted that it always should be even -> got max value and added zero sum. And it just works
yeah it was horrible..
I just guessed and counted odd values as well first.. but then saw the answer was near half of what I was getting and then guessed it will always be even .. lol .. shame on me.
Edit: Nvm I outputted x+1 instead of x.
Overall Good contest I enjoyed A, B and C.
How to solve B? C was easier than B imo.
It's too many conditions and too many if-elses.Need to carefully think of what if n is 1,2,other;and what if x is 0,1,other.
Here's my code.https://mirror.codeforces.com/contest/2108/submission/317970208
B was just greedy.. look at the binary representation of x and notice that all the set bits of X other than the 0th bit should come only once in answer if we want to minimize the sum and rest all numbers can be one.. Of course there is an edge case which was mentioned in sample cases as well 317990225 you can understand it from here.. For some reason i messed up C , i feel dumb right now, could have been a great contest for me but nonetheless will see next time.. Can you tell your approach for Problem C?
I know I failed in solving problem E, but knowing the solution of this seems to be a big help.
casework problem like B, can hell your whole contest xD
true, it is very sad when you get correct answer for open test cases but hidden pre-tests fail
exactly. idea is correct but missing edge case is too painfull :0
this round was harder than usual
The statement of D is so poorly written. It took me 20 minutes to understand that every $$$k$$$ consecutive elements of $$$A$$$ and $$$B$$$ are permutations of $$$1$$$ to $$$k$$$.
I wouldn't consider this poor writing, but rather an observation you have to make yourself. That was the easy part for me anyway.
True
What's wrong with my C 317997945
Try this case: t = 1, n = 5, a={3, 3, 4, 3, 3} The output should be 1.
how did you guys solved c ??
this is mine please tell me where it is going wrong
3
3 2 2
is a counter-example. Please, next time you upload code for others to execute/read, provide your typedefs and #define so others don't have to guess them.
thanks broo
Your code re-uses clones from nearby buttons without making sure the buttons are pressed in non-decreasing order
Struggled for A more than B,C. Overall its a good contest, atleast for me w.r.t A,B,C
Finally a contest where accepted solutions for A, B and C seems human rather than LLMs
As a participant I Realllly enjoy in that constest
What was tc 4 in D, kept getting Wrong answer on it T_T
casework for B is like sooo worst
Overall good contest, was able to solve A,B,C.
I was trying to solve D using binary search, and was not able to implement it during the contest, will upsolve. Anyone who has done it using Binary Search???
Yes, that is the intended solution
Yes, I used binary search: https://mirror.codeforces.com/contest/2108/submission/318001761
EdgecaseForces
what the hell is the 7th test case for D?
E was easier than B imo
Okay smarty pants, GM when ?
Copy-pasting doesn't change in difficulty depending on the problem
Rating is going to take a huge hit after this round. I can usually solve atleast 1-2 questions in div2. Could not solve any this time :(
If you haven't submitted anything, then your ratings are unaffected.
I get it, this A was based on observations about the possible values of the sum, which aren't that straightforward at all. B felt around the same difficulty as C. B was kinda heavy on casework, and C was even more observation-based with an easy implementation.
Wasn't there supposed to be a contest on saturday(3rd of may)?
yes there will be another contest on the 3rd
Well..it doesnt show up and i remember it was from those guys who made round 1021 which got a lot of hate cause of poor statements hopefully they dont back down on us:)
very good Div1 guys
can someone tell why my solution for c is failing ? 318011548
you might want to try out this test
Output is 3
Amazing problem D ! thanks for the authors for that but I which C and B was more interesting.
Worthless idiot like me deserve to be butchered like a pig. I practice and solve 2200+ rated problems without editorial and get 2000 performance in virtual, then reality says fuck you and I don't solve Div2B. Every time I do virtual it's CM performance but real contest I get 1600? Why? I love solving problem but every time I do contest I get severe depression the whole day after, maybe best I quit CP before I develop some mental disease.
dont be so hard on yourself.. keep practicing .. it will take some time.. but it will improve..
anyway if you are able to solve 2200 problem I should not give you advice... lol
this B was just a bunch of casework and the contest overall was bad, did you try solving C or D after not being able to solve B? you probably got really panicked after not being able to instasolve B and then you ruined the entire contest. i couldnt instasolve A this contest, and i coyuld have panicked as well, but you really just have to keep calm and relax in those situations. and in the end after taking 10 minutes to solve A, i had a CM performance, because i kept calm and read B before returning to A with a clear mind. all of this will come with experience and you shouldnt beat yourself up after a bad contest. especially since you really have nothing to lose in these contests except virtual points. making mistakes is important in these online contests, so when you do irl contests you can avoid them
c was trivial compared to b...
so yeah b is a really ugly outlier (stress test forces)
pretty bad contest, speedforces with ABC, and then a really hard D. i find D really cool even though i didnt solve it, and i think i will enjoy upsolving a lot, but the overall balance of the contest is terrible(even though this is my best performance ever in any contest and i think i will even reach expert lmao)
I solved D with binary search, I think it's actually easier than most div 2D
it seems i was on the right track then, but just couldnt finish the problem :( nonetheless, i still think the difficulty difference between B and C is 0, while the difference between C and D is massive
I think compared to normal 2B, 2C, 2D:
B today was slightly harder C today was significantly easier D today was slightly easier
so yes the diff between C and D was a bit more than normal
also congrats, looks like we both are expert for the first time
lmaoo nicee, congratulations to you as well
When is editorial coming out??
can someone help me about how can i try and run the first testcase of interactive types problem?
I don't really think there is a way to run interactive testcases because the result is always hidden by the jury.
are you asking how to test interactive problems on your own?
You can
Tags for A are trying to say something
banger round, one of my favs thus far <3 thanks to the writers and testers orz
Thanks:)
Trolled myself in C
only after finishing the buggy implementation did i notice you could move any clone, not just the newest one
A -> observation, Maths B -> Bit Manipulation. Greedy
how do you solve E? is it just look at the diameter and remove a leaf not on diameter, otherwise remove a leaf on diameter? or is there more lol
also ty contest creators, not bad round + i promoteforces :]
Consider the tree, rooted from it's centroid, in this case lca of each pair with same color is root of the tree and we should merge the vertex $$$v$$$ with the minimum $$$h[v] + sz[v]$$$, where $$$h[v]$$$ is the number of edges from $$$v$$$ to root and $$$sz[v]$$$ is size of the subtree with root $$$v$$$.
For $$$D$$$ 121/122 queries are enough
yep, 2k + log(n)
yeap, but look at c->d correct solutions gradient:D
Ordering of B and C should be swaped .... . Problem B was a little nightmare ..........
The standings show that nothing needs to be swapped
truly based
The less submissions of C is only because of problem B . Many people stuck at it ......
Many people got stuck on B and never even look at C
Excuse me, why do I get a Memory Limit Exceeded (MLE) error in this C programming problem? 318031123
since you are using priority queue, you probably have a logic error that results in you pushing extraneous nodes (perhaps infinitely) into the priority queue
D was a very fun problem, probably one of my favorites!
The key idea is to notice that both $$$A$$$ and $$$B$$$ consist of a repeating block of $$$k$$$ distinct numbers. This means that $$$A$$$ and $$$B$$$ are both uniquely determined (apart from length) by the first and last $$$k$$$ characters respectively.
We first query the first and last $$$k$$$ elements. Using this information, for any index, we can find its value if it belongs to $$$A$$$ and its value if it belongs to $$$B$$$. Some indices modulo $$$k$$$ will have the same value in both arrays, but others will be different. By querying the latter indices, we can binary search on where the boundary between $$$A$$$ and $$$B$$$ is. (If all indices have the same value in both arrays, then the answer is $$$-1$$$.) This will take $$$O(n)$$$ time naively, but we can optimize this to $$$O(k+\log{n})$$$ time by using the fact that the indices repeat modulo $$$k$$$.
The boundary must lie in between two of the latter type indices. If those two indices are adjacent to each other, then the boundary is uniquely determined. Otherwise, it cannot be determined. This solution runs well under the query limit.
Remember to account for the edge case where one of the arrays has length exactly $$$k$$$.
S
Can you please tell why this algorithm failed on C?
The code below works (318056161). I just removed non-unique consecutive elements.
Your code fails on this test case:
Basically it marks first $$$5$$$ (and increase the answer). Then it goes to the last $$$4$$$ and as the middle $$$4$$$ is not marked it increases the answer again. So it gives the answer $$$2$$$, instead of $$$1$$$. We go $$$5 \,\rightarrow\, 4 \,\rightarrow\, 4$$$.
Is there a more straightforward observation to get the answer for A? I had to do the following:
Hence, the answer is always just $$$\frac{h_{N}}{2} + 1$$$
When I was solving, I just guessed the answer. After the contest I came up with this:
Great contest. Thanks!
I read the Problem C for an hour.I thought the clone means another copy of a button. What can I say.
Solved the problem C using DSU: https://mirror.codeforces.com/contest/2108/submission/321019754