Hi Codeforces!
I Serval am glad to invite everyone to participate in Codeforces Round 1011 (Div. 2), which will be held on Mar/22/2025 17:35 (Moscow time).
This round will be rated for participants with rating lower than 2100. We will be glad to see the participants with a higher rating to take part in our round unofficially as well!
You will be given 6 problems to solve in 2 hours, one of which will be divided into two subtasks. Scoring distribution will be announced later.
I would like to thank everyone that makes this round possible:
- Error_Yuan and satyam343 for coordination of the round and help with the preparation. It is noteworthy that this round is the debut of Error_Yuan as the coordinator. Special thanks to him!
- 18o3, AG-88301, Dominater069, Edeeva, Graythron, Hanghang007, JagguBandar, Friedrich, N_z__, Nerovix, Proof_by_QED, RDDCCD, RTE, SSerxhs, SkyWave2022, SpyrosAliv, StarSilk, _istil, chromate00, darkkcyan, guangmingzhengda, larush, macaquedev, mathtsai, temporary1, tiger2005, yoru_sacri for testing the round and providing valuable feedbacks.
- Alexdat2000 for Russian translations of the problemset.
- MikeMirzayanov for the amazing Codeforces and Polygon platforms.
- You, for participating in the round and gaining a positive delta.
Good luck & Have fun! (∠・ω < )⌒☆
UPD: Scoring distribution: 500 — 1250 — 1250 — 1750 — 2500 — (2000 + 1000).
UPD2: Editorial is out. Congratulations to the winners!
Div. 2:
- sounansya
DuyNgaDocTon1410Disqualified. - SoloRE
- nocap
- Asbjorn
- AksLolCoding
Div. 1 + Div. 2:








As a coordinator, I was playing Genshin with the author!
As a tester, I think Serval is a cool character in Star Rail
Actually Serval is from Japari Park. :P
I am sure that Serval is a cool character in Japari Park as well
As a tester, how much are you affiliated to kyopro_friends on atcoder?
Here comes :
Good luck everyone!
As a participant, I recommend all of you to watch Kemono Friends. (BUT NO ONE SHALL WATCH SEASON 2!!!)
;gimme 1603
How to be a tester ?
I wish we could have a
add this blog to the home page?
As a tester, I'm too late...
As a tester serval is a super cool character who displays indirect buffing so well. After the introduction of the herta serval skyrocketed into a meta sub dps due to driving her super so well when using s5 passkey. But she'll probs fall off again like every good 4 star like gallagher or Moze
WOW~~~~~~~~~
as somebody who was supposed to test, my pc still isnt fixed and im writing this from my phone :(
As an 8-year-old girl, Hope to solve two problems in my first codeforces round.
UPD: I do it!
You'll make it, just believe in yourself.
Wow 8 years old girl
As an Eight year old
啊~啊~啊咦~啊咦~哦→啊↑啊↓啊~嗯~哎哎↑哎哦哎嗯~哦啊~爱↖爱↑爱↗爱↑爱↑啊~啊~啊咦~啊咦~啊→啊↑啊↓啊~嗯嗯↓嗯↓滴嘚滴嘚唔↑~~嘟←嘟↖️嘟↑嘟↗️嘟→嘟↘️嘟↓
Unfortunately, the problems are 2085 but not TECHNOPOLIS.
caused by 2085
2085 nerd
First contest I take this month, hopefully reach master
orz
I hope the problems are not a pile of crap.
aiming for the blue color...
hope that it will be a good round for everyone... && hope that cheaters will not participate in this contest..
youre already blue.
so, are you violet?
sure.
Why is this round special?
It's the last binary round of the era, and the last binary contest of our lives. ^-^
sorry sorry! I forgot..! tnx!
1100 1101 1110 1111??
lol I forgot about them!
I wish this round is good and we all can reach high rating.
Hope to see you as Candidate Master today...
Good luck & Have fun! (∠・ω < )⌒☆
Ciallo (∠・ω < )⌒☆
As a tester, I enjoyed the problems more than the bananas
There will, and there shall be a Serval round!
Good luck have fun everyone.
I hope it goes well.
^-^
I'm like very new, so how does a contest work?
Note that the contests vary in difficulty. It can be Div.1, Div.1+2, Div.2, Div.3, Div.4, where Div.1 is the most difficult and Div.4 is the easiest. Normally Div.3 and Div.4 are for school pupils, Div.2 for university students and Div.1 for pros. Actually, you can participate in any.
Practice with the problems from previous contests, register for the contest, prepare mentally for a sprint, start in time and do your best!
As a tester, I think the problems are very Serval.
Is there some specific reason the email announcement for this contest did not mention Rust in the list of accepted languages?
[off-topic] you are so nice man. you been 1600 rated by 4 contest nice. What's your first account? or it is first?
First account here. If you want a better look at my CP activity in recent years, you can also check out my leetcode account.
Answering to myself: it was actually available during the contest, so likely just an error?..
GLHF everyone except cheaters!
Here's an image of the standings after 1 hour. Anyone can see a pattern here
Solved C in 5 minutes and then staring at D, i hate these speedforces.
whoa man... C was kind of hardest for me today
and tbh it was 2nd easiest for me after A like I knew the identity so it was damn easy
yeah i am reading other threads which say
2^X - max(a,b).. like seriously ... I almost cried lmao.anyway u learned something XD, I was lucky that I studied this identity on cf blogs some 2-3 days ago only which I remembered this is that blog u can read it too
oh man, I really need to practice bitwise things... so confusing always.
thanks for sharing this blog
after long time I made all questions (A -D) with logic and not much guesswork .. finger crossed for system test
unfortunately I made wrong submission for div2B .. indices should be with respect new array LOL...
hello "expert" my old friend / rank
I come to talk with u again
hello fellow programmer.. did we meet before ?
No, just kept up the lyrics of "the sound of silence".
oh I am sorry to ruin the fun ... ha ha .. I am noob in song lyrics
how to solve C ?_?
WLOG, let x < y. Then, add to x and y such that x only has a single bit. Then, if x and y still share a bit, do the same thing to y. You can easily enough see that x and y will not share bits after this due to x < y in the first place.
can you show your code
Since the range of x and y is $$$10^9$$$, and the range of k is $$$10^{18}$$$, we can always find a k such that
max(x,y)+kis a power of 2.Well, first if $$$x = y$$$, there is no answer, clearly.
Otherwise, let's say $$$x \gt y$$$ (if not, we can swap), you want to make $$$(x + k) & (y + k) = 0$$$, which gives an idea of making $$$x + k$$$ having one set bit, which is $$$2^p$$$ ($$$2^p \ge x$$$). When we have $$$x + k = 2^p$$$, $$$y + k$$$ cannot reach $$$2^p$$$ since $$$x \gt y$$$, so they won't have common set bit.
So result is $$$2^p - x$$$.
Spent almost the whole contest and couldn't find this simple trick. How can you train your mind to think like this, really...
We know for all x,y that x ^ y <= x + y. And the equality case is when there are no shared bits between x and y. So you need to add some k to both x and y such that they no longer share bits.
Agree. Thinking about inequality would definitely help find the trick. Guess I'm not trained enough for that then :)
Accidentally I think. So I first wanted to make them having no common set bit, but adding
1like the test19 10is kinda tricky, I was in fact stuck. But then I thought what if I could make one set bit instead, then I saw they must be different from the start (because if they are equal, result is-1). Ohhhhh!That was my thought process.
Yeah from the start seems to be the key here. I was too busy trying to turn
1bits inx & yto0and got stuck. Shame on me.jiangly also did this, how you guys find these things?
Hey, I left a comment to answer the same question above. You can refer to it https://mirror.codeforces.com/blog/entry/140825?#comment-1258000
Amazing, Explanation.
oh man, this is so cool
2^30 — max(x, y)
it will make the larger number something like 100...0000 (1 followed by many zeros). Xor of any number(y + k) will always be the sum of this number and y+k, since there will be no carries involved.
what is the general idea for solving c
Make the maximum number power of 2 and if number same then -1
One of xor identity: x + y = x^ y when there's no bit of x and y are equals.
So you need to find a k to flood max(x,y) to 1 bit to the msb(most-significant-bit) only, the lesser number cannot reach there and there you have it.
the formular:
I accidentally AC, then realized this after AC rofl.
C was too difficult for me..
speedrun through ABC but stair at D and F1 till the end of contest.
lol, the terrible C did not allow to solve the interesting E and F1. Why do we have to play guessing games all the time?
how to F1
My solution
Wow im an idiot i decided to both pick the middle AND the subarray in question so i was wondering what monster data structure to use to optimize it to $$$O(n^2logn)$$$
I really hate problem of kind C if you know the 'gimmick'
a + b = (a & b) << 1 + a ^ bthen it's free otherwise you are screwedI find the fact a + b = a ^ b <=> a & b = 0 pretty obvious, if you just observe the bitmasks.
Well now in future problems u'll know, as it is pretty standard result used in multiple problems.
First, it is well known; Secondly, it is not hard to observe that $$$(a+b)=(a\oplus b)\Leftrightarrow a\operatorname{\&}b = 0$$$. You just need to look at the binary representation.
I didn't know that beforehand, derived it mid-contest
Please explain C in simple and step by step how to solve. Thanks in advance for your help....
the easiest way to understand is to try and add two numbers by hand in binary, then try to xor them in binary. What you'll find is xor will equal addition if there is no "carrying" of the bit.
note that a+b=(a&b)<<1+(a^b) so now you know that (x+k)&(y+k) must be 0 note that if x!=y one is larger, so if you add diff between larger one and 1<<(msb+1) to both of them, one will have all 0s in the original places and one in the larger place, other wont have that 1 in the larger place, meaning & of the two is 0, meaning its euqal a+b to a^b
gg
note: take the larger msb of the two if they differ
$$$2^{50}-\max(x,y)$$$
nooooo!!! how do I unsee this .. aaaaaaaaa !!! I spent so much time on this one.
use 'well known' equality a + b = (a & b) << 1 + a ^ b
then you will find (x + k) + (y + k) = (x + k) ^ (y + k) iff (x + k) & (y + k) = 0
wlog let x < y, let X = x + k, and d = y — x. then X & (X + d) = 0. then it's fairly easy to find X
I stuck at D by thinking about dp, nooo
I submitted dp solution only to a TLE in pretest 3. How to D? Cute and simple problem but just aaaghhhhh!!!!
me too~ When doing the exercises, I really want to know what test case 3 is.
me too... At the last minute of the contest I realized that this problem could be solved using greedy algorithms with heap. But I don't have enough time to solve it >_<
I also thought about dp for D and stuck for a long time, then attempted F1 but failed too...
wow you are able to attempt F1 that is very cool
not so cool when I don't even realize I got stuck in pretest because of this cursed test case
still cool for me because I couldn't even attempt.
also just want to confirm that failing pretest doesn't affect other problem's score right ?
penalty only comes in action when you are able to make a correct submission right ???
failed in test 1 doens't count penalty (in case you're lazy to write checker function or test locally)
oh I see, thanks
ha ha read hint 1 in the editorial LOLOLOL
Fun Contest! Thank you for the problems.
How to solve D ? Can we use dp ?
We can use priority queue.
yeah Jiangly used the same !!
Let's go backwards. If at some suffix you know what's the best you can do, then when you add another plate at the start, there are some choices:
Take it, if there's enough time to finish it in the future
If it can't be just taken, and before you took a plate with lower value, then you can switch them and improve the answer
I did the same, I was very happy that I didn't miss any corner cases as well.
I may be stupid but I don't understand why d[i] + extendable_suboptimal_solution_for_suffix can't be better than d[i] + best_solution_for_suffix — smallest_val_in_best_solution in case when we can't extend the best solution for suffix
By definition, every extendable suboptimal solution can be extended to make it not extendable, and let’s say, it is extended in the best way. From that non-extendable solution, the best we can do is switch the current value by the smallest in the solution. And as the current solution is the best of that kind, then it is optimal to stay with it and make the possible changes
I was confused about the case when it's extentable with the current element and isn't with any element to the right, but I think I got it now.
It probably should be intuitive, it's totally not for me, but I did some math and found out that in this case the extended suffix will contain the maximum possible number of plates. And I spent some time understanding that the best solution for suffix should also contain this number of plates because it can't be extended(again, it wasn't intuitive for me that a good solution can always be extended if the number of plates in resulting solution won't be greater than the maximum for the extended suffix(I thought it may become bad after extending), so if a good solution can't be extended it should contain this maximum number of plates to "overflow" after extending, it's the only way it can become bad). And as the number of plates is equal the modified best solution is obviously better.
D was a cute problem.
E problem statement was also very easy to understand, but solving it was not so easy for me.
Can anyone hack my submission for E?
It's basically just bruteforcing over all possible k(found from using the max of a and the differences with the elements of b), but pruning the amount of k with some optimizations.
I got a sum total of 8 WA by being stupid and not realizing I wrote it wrong :(
Interesting problems, really brainstorm. I like it and it let me become CM:))
Can anyone share solution to F2?
only GMs can do F2 I guess.. ha ha
How does E work?
yeah me too waiting for editorial for this.
If $$$b$$$ is a permutation of $$$a$$$, then any number larger than $$$max(a)$$$ is OK.
If $$$sum(b) \gt sum(a)$$$, the answer is $$$-1$$$.
Otherwise, calculate $$$d = sum(b) - sum(a)$$$, $$$k$$$ must be a factor of $$$d$$$.
Enumerate each factor of $$$d$$$ and test if it satisfies, with 2 optimizations:
(1) $$$k$$$ is larger than $$$max(b)$$$; (2) If $$$k_0$$$ is not the answer, the multiples of $$$k_0$$$ is not, either.
If no such $$$k$$$ exists, the answer is $$$-1$$$.
my solution
UPD: My solution was too complicated when calculating the factors of $$$d$$$. x_x
oh thank you for sharing your thoughts.. I will try to understand this tomorrow and try to upsolve E
Let's assume that array b is arranged correctly. This means that a[i]=k*q+b[i], where q is some non-negative number; This means that sum of a is equal to k*m + sum of b. So if we substract sum of a from sum b, we get some number that is divisible by k. So K is one of the divisors of (sum a — sum b)
You can just iterate over each of the divisors of (sum a — sum b) and check if any of divisors can get you an array which is equal to b.
Note that you can reduce the number of divisors that you have to iterate through, because k is greater than maximum of b (a % k < k) and a%k=a, if k > a, so k is less than maximum of a, if array a is not equal to b, or k is just any number bigger than maximum of a, if a is equal to b.
Genius! Thank you.
noice..
Fun fact: I Wrong answer on pretest 2 on B for 4 times, and the time I used to solve B is equal to the time I used to solve D + the time I used to solve E.
whoa you solved E . please share the idea behind E
$$$\sum a = \sum b$$$, so $$$\sum a \bmod k = \sum b \bmod k$$$, $$$\sum a - \sum b \equiv1\pmod{k}$$$. So just try every factor of $$$k$$$ and check if it's correct.
By the way, if $$$\sum a \lt \sum b$$$, then it has no solution. If $$$\sum a = \sum b$$$, then just pretend $$$k = 10^7$$$ and check if it works.
oh man,, thanks a lot.. please take my rank and I will take yours.
oh ratings got updated, and now you are higher rated than me... congrats and well deserved.
Thank you^^
A nice contest!
very fun and interesting round i loved b and c in particular, codeforces just doesn't get better than this
311834563
First time I'm commenting something, so my bad in case of any mistake.
I don't know why my code is giving WA on problem A. I tried to think of test cases which may be the issue but I failed to come up with that. After contest to check the failed test case, it was 353rd token on pretest 2, so I couldn't read that. Just as a last resort, I tried AI to understand the flaw in my code but that didn't work either.
Thanks in advance, for any reply/help
try this case, although I didn't see your whole solution .. this caught my eye quickly
it was 353rd token on pretest 2, so I couldn't read thatYou can actually
submission
wrong output format YES or NO expected, but 4_0_JJOJ found [353rd token]
so testcase is
1
4 0
JJOJ
Thanks! this will come in handy in future as well
Could anyone prove the time complexity of my solution for E or hack it?
Here are two versions of it: 311889161 and 311897982. The only difference of them is explained in bold.
Without breaking the loop, the time complexity will be $$$\mathcal{O}((\text{distinct number of divisors of a)} \times n)$$$, which should have a far greater number of inner loop iterations than just $$$n^2$$$, but 311897146 this submission shows that it didn't even run $$$5$$$ million times on any of the tests due to the
break.The version that does not break the loop still passes in $$$531$$$ ms, but it's certainly because of the tests being weak, since I was able to make a test that makes the loop run $$$\sim 322$$$ million times, although it still wasn't enough to be hacked and it passed in $$$1671$$$ ms. Could anyone hack this version, at least?
I tried hard hacking this kind of solution during testing, but never succeeded.
At least I managed to hack the version without
break: https://mirror.codeforces.com/contest/2085/hacks/1121319This test makes the loop run $$$\sim 750$$$ million times, but I'm pretty sure there exists a much worse case.
Thanks!
I also had a same solution as well. Mine ran around 1948ms with the hack test. Not sure if it is hackable or not.
Hacked :)
The difference between your solution and mine was that you subtracted $$$\max(b)$$$ instead of $$$\min(b)$$$ so maximizing the number of divisors didn't go well on your solution because it had $$$b[1]=1$$$ to guarantee that there exists no valid $$$k$$$. So I just needed to increase every value in $$$a$$$ by $$$1$$$ to make your solution run similar as mine. Also, the test I used to hack your solution makes the loop run $$$\sim 930$$$ million times which is even worse than the ones I used so far.
Thankyou
I found problem C a lot harder than problem D. I ended up solving it with dynamic programming to find the minimal value of $$$k$$$.
Is top 2 of today div 2 abusing AI to cheat in this contest?
Very suspicious
They used some scuffed dp sol for C instead of the extremely simple O(1) solution. AI is known to struggle with ad hoc but is better at dp problems.
They also failed pretest 1 on several submissions, and even submitted some compilation errors (that have nothing to do with compiler).
Also
constexpr int INF = 1e18on D is crazyServal MikeMirzayanov pls investigate
Just look at their previous contest lol its a blatant cheater
Screencast with commentary
Well, if you see the tutorial, you will see that there exists a much easier for F2 than just going for DS bash. I hope you will like the linear solution.
Enjoyed the contest mostly because it was more on thinking about the problem rather than just being some derivation of some standard problems.
I'm stupid. Can anyone point out the bug? It passes the first test and fails on the 88th of the 2nd pretests.
https://mirror.codeforces.com/contest/2085/submission/311931598
my bad
That's alright. I'm quite new to this. And this was my first contest. I couldn't figure out a counter example to my logic
now it should be right
1
6 1
bbabba
ahh thanks man. solved it. DAMN I WAS THIS CLOSE! Will do better next time hopefully
np and I recommend to check the editorial for simpler solution
Yes i did check it. But i just wanted to make sure that my solution was valid or not. Thanks
I gave you my While loop handling — ~~~~~ while (t--) { int n, k; cin >> n >> k; string s; cin >> s;
// If the string has only one character, it's not universal if (n == 1) { cout << "NO\n"; continue; } // If all characters are the same, it cannot be universal if (count(s.begin(), s.end(), s[0]) == n) { cout << "NO\n"; continue; } // If already universal, print YES if (isUniversal(s)) { cout << "YES\n"; continue; } // If at least one swap is allowed, we can make it universal cout << (k >= 1 ? "YES\n" : "NO\n"); }~~~~~
i managed to solve it after the person above gave me a counter example to my solution. Thank you for taking ur time to help me out
Just curious
For Div 2B the constraints were n <= 5000
was it becuase of implementing the checker or simply to confuse Serval
The checker runs in $$$O(n^2)$$$ because of the array manipulations in each operation. An $$$O(n^{1+\varepsilon})$$$ checker needs some DS to optimize it. Leave it as homework. :)
Top 5 lets go!