Hello / Selamat sejahtera / 你好 Codeforces! ^.=.^
We, CSQ31, Evirir, and YouKn0wWho, are excited to invite you to Codeforces Round 994 (Div. 2) on Dec/20/2024 17:35 (Moscow time)!
In this round, you will learn more about Evirir the dragon and help (or stop) them as they wreak havoc and escape from a wizard.
You will solve $$$6$$$ problems in $$$2$$$ hours.
The score distribution is $$$500 - 750 - 1000 - 1750 - 2250 - 2750$$$.
There will be at least one interactive problem, so please read the guide for interactive problems if you are unfamiliar with them.
We would like to thank everyone who made this round possible:
- Kaey for coordinating the round, coming up with ideas and solutions, and helping with preparation;
- Alexdat2000 for translating the problem statements to Russian;
- A_G, Alpha_Q, Darkeld, quacksaysduck, francesco, JOliva, Friedrich, OMARB, shaili17, Tainel, and whiitex for testing our round and providing useful feedback, praises, and flames;
- You for trying out our problems; and
- MikeMirzayanov for the amazing Codeforces and Polygon platforms that support contests beyond Codeforces contests.
Fun fact: As far as we know, this is the first round by Malaysians since 2020 (last being Codeforces Global Round 10)!
UPD: The score distribution has been added.
UPD 2: Editorial
UPD 3: Congratulations to the Top 5!
Div. 2:
Div. 1 + 2:









Do you really think i will solve them?
Hoping for a fun contest!
hope to reach Specialist!)
Same
Same
finally, i did it
Congratulations
thanks)
frist connemt :D
:'(
Well you see, the question of "who asked?" is simply a paradox. Since by asking "who asked?", you are implying that people need to be asked before speaking. However following that logic, you would have needed to have someone grant you permission to say that, because who asked you to say "who asked?" ? Exactly, nobody did, and nobody can ask anyone to give them permission to give you permission because no one asked them. And this perpetual loop never ends, creating a paradox.
Created by @veryhungrydinosaur
Who asked?
Who asked you to say "Who asked?" ?
hope you all get greens give your best with best wishes
Don't curse me bro :(
orz Evirir
finally a contest with interactive, orz Evirir
don't make C as interactive make D or E or F
Problem G will not be interactive. Probably because there will be no problem G.
wdym, if there is no problem G then the proposition "Problem G of this contest is interactive" is vacuously true 🤓
Studying first 2 discrete mathematics lectures for final exams be like:
🤓
how many interactives have you solved ever?
a big Zero
so then why do you think your opinion is relevant in any way? solve a few and then you will see that they are not bad at all.
can you suggest some easier problems to start?
https://codeforces.me/contest/1934/problem/C this one isnt the easiest, but its the problem i used as an introduction to interactives, also this one https://codeforces.me/contest/1520/problem/F1
https://codeforces.me/contest/1999/problem/G1 and this one is great as well
Happy?
Interactive problems are fun to solve. Isn't it?
Only if you are able to solve it.
Agreed
malaysian round lesgo
Hope no negative delta this time.
AAT, I really enjoyed the problems: it’s well-balanced and has something for everyone. Hope you all have fun solving it, too. GL orzz
judging by the drawing, this is going to be a banger [fire emoji lol]
the frog is so cute...oh! its a dragon,my bad
LOL☠️☠️
orz CSQ31 orz Evirir rawr >////<
Score distributions??
As a participant, i'm afraid of interactive problems
Cute dragon.
The FBI told me this round will indeed have problems.
You will solve 6 problems in 2 hours.Tks!Really? Meoww~~~~~~~~
Wait... 6 problems and 6 dragon balls? Are we summoning Shenron or debugging our way to a wish?
dont make interactive problem in A-C
Shield fan
dragon ball fan
real
Why not?
Tahun baru kehidupan mu menjadi lebih baik
It's almost time guys,give us the score distribution.
Score distributions?
I guess 4th problem will be interactive or any easy 3rd problem as interactive
my guess 5th. let's see :p
SpeedForces incoming !!
MexForces
Is E binary search on k? If yes, how?
I am wondering the same question. I tried multiple ways, I mean n has a constraint of 2^30 and there are 33 queries so there must be some sort of way to binary search on answer.
Yes, its binary search.
Lets first split the array into 4 equal sized ranges. This is clearly possible since $$$n$$$ is a power of $$$2$$$ and at least $$$4$$$.
If we queried these 4 ranges, we would either get back:
3 "0"s and 1 "1", indicating that 1 represents the range with the hidden value, and thereby $$$\frac{n}{4} \lt k$$$. In this case, we binary search on the size of the range $$$[l, r]$$$, always ensuring it completely contains the range which returned $$$1$$$. Since this range will always contain the hidden value, the smallest size where the value becomes $$$0$$$ is your answer for $$$k$$$.
3 "1"s and 1 "0", indicating that 0 represents the range with the hidden value, and thereby $$$\frac{n}{4} \geq k$$$. In this case, we binary search on the size of the range $$$[l, r]$$$, always ensuring it remains completely within any range which returned $$$1$$$. Since this range will never contain the hidden value, the smallest size where the value becomes $$$1$$$ is your answer for $$$k$$$.
This naively takes $$$4$$$ queries for the first part + $$$30$$$ for the binary search which is $$$1$$$ too much. But we can notice that the result for the 4th segment can be uniquely obtained from the query results for the first 3 segments, reducing our total to $$$33$$$ queries.
Code — 297544715
Nice problem, thanks
Nice problem and interesting solution!
During the contest, I tried to split the array into $$$2$$$ equal sized ranges, then I was struggling with how to determine whether the return value is case $$$s(l, r)$$$ or case $$$1-s(l, r)$$$.
I did not notice that by splitting it into $$$4$$$ equal parts, it is possible to identify the return value through counting number of $$$1$$$ and $$$0$$$. This is a really unexpected idea for me.
Thanks for your prompt solution reply!
I tried to first do 3 queries on range [1, n/4], [n/4+1, n/2], [n/2+1, 3*n/4]. That way you can find where the 1 is present and if k is greater or smaller that n/4.
Afterwards ask for [1, n/2] in case k >= n/4. If with that you discover k >= n/2 then you search including the half you know contains the 1, otherwise you search in the half you know it has only 0s. This way you can binary search as the function changes from true to false at a single value which will be k.
I think the idea is right but wasn't able to implement correctly, please let me know if somebody finds any flaws.
I did 3 queries:
with first query I can determine which of [1,n/2] and [n/2+1,n] gives answer 1 (because these two intervals have to give different answers.
the chosen interval [l,r] is divided into two halves [l,m], [m+1,r] and they are queried.
If those two answers are the same: that means [l,r] doesn't contain 1, and we also determine if k is in range [n/4+1, n/2] or [2, n/4].
If the two answers are different: that means the [l,r] contains 1 and k is in range [n/2+1, n].
In all these cases, the remaining part is very simple binary search on k.
Solving D too slow made me fail to return CM, nooooo...
F is cool
Question B's n constraint of 5000 kinda confused me for a bit, for a moment I thought it was brute force, tho it turned out O(n) is enough.
Problem, Problem B.
"Submit code for E": 0:00:09
The submit site done loading: contest over.
Screw me over....
agghhhhh, I solved B and C so slowly :( and just almost solved and implemented D in time.
Slow specialist like us are tend to eat dust from the expert + CM. Time to upsolve and practice some more haha
this contest was a pain in the ass
Yeahhh!! There goes my rating .
2049A - MEX Destruction = 1696B - NIT Destroys the Universe
Solved the latter 2 days back so this was a treat
MEX FORCES
Is there something wrong with the tests on D? Why did my N^4 solution passed?297536216
It could be TLE on the main tests.
Somehow passed also. Monkalaugh Monkalaugh.
O(N^4) for N^2 == 50 000 and 2.5s sounds like it might actually fit. I might hate myself for not trying that solution... I literally thought about it...
How to C?
do MEX operation as problem said, repeat it 10 times (probably only need 3 times, but I rather 10) and you AC
Fix $$$x$$$ and $$$y$$$, then brute force every other position. You can see that there exists an answer with element value never greater than $$$3$$$.
Can you please elaborate a little bit,i couldn't understand why and how?
Without loss of generality, assume $$$(x, y)$$$ as $$$(1, y-x+1)$$$ (as the array is cyclic).
We'll see that friends should have different value, thus we can fix $$$a_1 = 0$$$ and $$$a_{y-x+1} = 1$$$.
Loop for all $$$i$$$ in range $$$[2, n]$$$ except $$$y-x+1$$$. Initially, $$$a_i = 0$$$. Keep increasing it until the first moment it is not equal to any of its known friends (known = elements that had been set before, that would be anything previous $$$i$$$, $$$1$$$ and $$$y-x+1$$$)
You can also do it without ever using 3, i.e., using elements 0, 1 and 2 only.
If $$$|x - y| = 1$$$, then if $$$n$$$ is odd, print $$$2, 1, 0, 1, 0, ....$$$, and if $$$n$$$ is even, print $$$1, 0, 1, 0, 1, ...$$$. If $$$|x - y| \gt 1$$$, if the number of dragon between $$$x$$$ to $$$y$$$ and $$$y$$$ to $$$x$$$ is even, then print $$$1, 0, 1, 0, 1, ...$$$, otherwise let $$$a_x = 2$$$, $$$a_{x + 1} = 1$$$, $$$a_{x + 2} = 0$$$, $$$a_{x + 3} = 1$$$, ... (I draw all of those cases and saw the answers LOL).
If there wasn't another condition on x and y, then the trivial solution is
But when there is another condition on x and y (And if they have the same parity), then you will have to make either a[x] or a[y] equal to 2 too. (Note: There is an edge case when n is odd and x == 1, y has the same parity as x, then you will have to make a[1] equal to 2 instead of a[n])
First, think about a simple cycle of size $$$n$$$. If $$$n$$$ is even, $$$[0, 1, 0, 1, \ldots, 0, 1]$$$ is an answer. If $$$n$$$ is odd ($$$n \ge 3$$$), $$$[0, 1, 0, 1, \ldots, 0, 1, 2]$$$ satisfies the condition.
For this problem, there are at most two cycles in the graph, and they share exactly one edge. You can allocate $$$0$$$ and $$$1$$$ to the two vertices the shared edge connects, and do the above for each cycle individually.
hopes shattered!
Ok, I'm absolutely stumped by WA on test 1 in E.
My submission correctly guesses "5" for the first sample case when run in Codeforces custom test and locally (tried compiling with both -g and -O2) but incorrectly guesses "4" when submitted.
All queries are small enough to safely verify by hand ((1, 2) --> 0, (3, 4) --> 0 and (5, 6) --> 1) or the responses are present in the sample ((4, 8) --> 1 and (3, 8) --> 0) so I doubt that's the cause of the issue.
I also don't see any obvious undefined behavior in the code:
Can someone help identify the undefined behavior (or mistake in my query responses) that are causing the difference?
Edit: I know there is a different bug in the code for the
if(cnt_ones == 3) {block, but the samples don't run it.For $$$k = 5$$$, the response for $$$(4, 8)$$$ would be $$$0$$$ since range contains $$$1$$$ $$$($$$at $$$6)$$$ and length $$$= 5$$$ is atleast $$$k$$$.
Oh, test case 1 and the sample are different...
I looked at the output of test case 1 and the explanation of the sample even though those clearly make no sense together >.> (using $$$k = 6$$$ for calculations and considering $$$k = 5$$$ output correct lol, my brain was clearly fried today)
losing too much time on ABC sadly, could've have enough for solve 1 more but I can't... maybe next contest :(
Is there beautiful solution in C? Because my solution is $$$ififififif$$$.
You can break the big cycle down into 2 small cycles defined as (1) in between x and y, and (2) outside x and y. ans[x] = 0, ans[y] = 1. Then, for each cycle, we separately start from y and work through the cycle back to x, just alternating the values being 0 and 1. If we return all the way back to x and find that we placed 0 and 0 adjacent to each other, we make that last-placed value a 2.
I don't know if it's a beautiful solution but here is my solution : 297477253. I know that a[i]<=2, so for each i, I create a set containing 0,1,2 and erase a[i-1], a[i+1], a[x], a[y] if I've already calculated their value, then I take the minimum (I have no proof of why it works but it seems logical).
I have solved with 0,1 only and then use 2 for the x,y cases:
B >> C
I thought B > C too while at it, but when I realize a trick in B it's simple
(I'm on panic af ngl, losing so much time shuffling between B-C, also losing too much unnecessary time on A because I'm late)
I came up with some bs solution for b, what is the easy way to do it?
Brute force :3.
brute force it coz n is small. The idea is work around left bound and right bound of an element
With every p or s, it limits the left/right bound. After that check if l<=r for all and no range is overflow (range of 2 can't contain 3 numbers)
Breh, that's what I did... ig I was just trying to shortcut a check to find if any range was overflowed and thus took too much time instead of being patient.
I too, was panic so bad and losing too much time...
I bet I can solve E with 30 more minutes sadly. (I pick E personally, coz I love interactives)
Also, NOOOO! ... I just realized right now that my implementation of D was all correct except for saying that i = 1, I had to say i = 0. This actually sucks.
?
ugh, ok, I get the error in D2, it's due to LL handling in cpp :(
Ad hoc forces, there goes my rating..
I suck so bad in solving DP problems, can you please share me best dp practice set apart from cses dp a problem/practice set with less no of problems but more to learn... plz
Exactly!! The standard dp is easy to identify but dp when in disguise like this, its becoming impossible for me to identify
Yup exactly, i am thinking to solve 1800 codeforces dp problems from now on then only i will become good in such problems
Problem A:is similar to https://codeforces.me/contest/1696/problem/BCan anyone help me understand B? i tried a brute force approach. 297536174
... soo i took a hashmap where for every 'p' i encounter i check for 1 to i+1 in the right half of the hashmap (from ind+1 to n), if element exists i simply return that array cannot be made and for every 's' i check for 1 to val (val being n-i+1) in the left half (0 to ind) returning false if i find matching element.
(sorry for bad english)
Is D Dijkstra?
Dijkstra can be used only in cases where the answer is monotonic.
I did Dijkstra correctly, but it's a bit slower than DP.
Your one already crosses O((n*m)^2) using three states and one loop. Its answer is monotonic.
I am talking about two states in which the answer is not monotonic.
Fair, thanks for pointing this out. Can you clarify in what sense the answer is not monotonic here?
I didn't understand, what do you mean by "monotonic"?
It's possible to Dijkstra this but it's essentially encoding the DP transitions as a graph and you get an extra log factor
My solution of $$$E$$$:
Note $$$left = ask(1, \frac{n}{2})$$$ and $$$right = ask(\frac{n}{2}+1, n)$$$, we can see exactly one of the following conditions holds:
Then we can choose either $$$[1, m]$$$ or $$$[m, n]$$$ to perform binary search.
Sadly can not implement in time ;)
Contest How much rating you want to lose?
Me: Yes
Screencast of me solving in rust (4k would be ready a bit later)
Is Mass Destruction the reference of A?
wow I didn't even think about it, very nice.
Codeforces Hot News!
Wow! Coder chenlinxuan0226 competed in Codeforces Round 994 (Div. 2) and gained -160 rating points taking place 4892
Share it!
Solution for d using recursive dp anyone?
Recursive Solution
Thanks
But we are not natural fruits :(
Too hard question for Div2 A. Hadn't expected this :(
Subject: Clarification Regarding Plagiarism Accusation for Problem 2049B in Round 994 (Div 2)[contest:994][problem:2049B]
Dear Codeforces Team,
I hope this message finds you well. I recently received a notification regarding my solution (ID: 297506801) for problem 2049B, stating that it significantly coincides with solutions Keylime/297472936 and tinytroubles/297506801. This notification has deeply concerned me, and I am writing to provide evidence and clarify that I did not engage in plagiarism.
Evidence Supporting My Case: Independent Work:
I worked independently throughout the contest and did not collaborate or share my code with anyone. Submission History:
My submissions demonstrate the evolution of my solution: Incorrect Submission 1: https://codeforces.me/contest/2049/submission/297498579 (submitted at 20:56 UTC+5.5)297498579 Incorrect Submission 2: https://codeforces.me/contest/2049/submission/297500380 (submitted at 20:59 UTC+5.5)297500380 Accepted Submission 3: https://codeforces.me/contest/2049/submission/297506801 (submitted at 21:08 UTC+5.5)297506801 These submissions were made within close time intervals, showing a logical progression in my thought process. Geographical and Logistical Impossibility of Collusion:
I am from India, while the flagged participant Keylime is from South Korea (Chung-Ang University). There is no possibility of communication or collaboration between us during the contest. Coincidence in Logic:
The flagged solution (https://codeforces.me/contest/2049/submission/297472936)[submission:297472936] appears to share similarities with mine. However, given the nature of competitive programming and the brevity of the problem’s solution, it is not uncommon for different participants to independently arrive at similar implementations. Additional Evidence:
If required, I can provide timestamps, drafts, and any other supporting materials to further substantiate my claim of independent work. Request for Re-evaluation: While I understand the importance of plagiarism checks to maintain the integrity of the platform, I believe this coincidence is an unfortunate case of two participants independently arriving at similar solutions. I respectfully request a thorough review of my case, as well as stronger measures to distinguish coincidental overlaps from actual violations.
Thank you for your attention to this matter. Please let me know if additional information is needed. I hope this can be resolved fairly and with due consideration.
Best regards, tinytroubles,tinytroubles ... expecting a change Evirir
This is my own implementation, and I have not shared my code with anyone or used any online tools like ideone. I implemented it entirely locally on my computer and followed my personal template, which I developed myself and use regularly for contests. Below is the template I used:
And here is the full code I submitted for problem B:
I received a message stating that my solution (link) is similar to another participant's solution (link).
The similarity might be due to the simplicity of problem B, which naturally leads to similar approaches among participants. Additionally, I submitted my solution approximately one hour earlier than the flagged solution, which supports that this is a coincidence.
I strictly adhere to Codeforces rules and have not engaged in any behavior that violates them. Please let me know if any further clarification is needed.
This in regard for the my solution to problem 2049B(solution-297500190) of this round.
Please check the code as i always use this type of variables in all my submissions before Kindly recheck it for further clarifiation.
Also problem 2049A is also skipped and I haven't got any notification yet.
the worst round of the year
Why? I love this round. My best ever, Rank 5.
and the problems had been good.
the most important problems for many people (CD) were bad — D is just obvious dp and C is annoyning constructive
can someone explain me problem b.