Hello, Codeforces! We're glad to invite you to take part in Codeforces Round 1031 (Div. 2), which will start on Jun/15/2025 12:05 (Moscow time). Note the unusual start time of the round. You will be given 6 problems and 2 hours to solve them.
This round will be rated for participants whose rating is below 2100. Participants with higher rating can participate unofficially.
The problems were authored and prepared by bashkort, TheEvilBird, 127.0.0.1, Mangooste and Moscow Olympiad Scientific Committee.
The round is based on All-Russian olympiad in the name of Keldysh.
We would like to thank
- Artyom123 for his high-speed coordination;
- A_G, ahsoltan, Proof_by_QED, larush, Mikhango, Ormlis, _istil for testing;
- MikeMirzayanov for creating Codeforces and Polygon.
Good luck everybody!
UPD: Score distribution: $$$500 - 750 - 1250 - 1750 - 2500 - 3000$$$
UPD2: Editorial








hope to reach 1750+)
+1
Nice i got -125 xDD
I got -122
Not our lucky contest I guess.
But for problem D in this round, you only need to learned binary search and prefix sums to solve it, and after solving problem D, the performance score far exceeds 1900...
hope to reach 1600+
hope to reach 819+
I hope you do
thanks)
I am aiming to reach Expert in or may be close to expert this round !! Hope the problem statements are enjoyable and interesting , and God bless everyone !!
omg, Mangooste && bashkort round!
That's a really short announcement ngl
Hope to reach specialist again.
me too:(
rating distribution? :pray:
only 5 testers?
probably because of how sudden and quickly they had to create this contest
Just try not to make problem B harder than C.
i guess they read that and did A harder than B
I heard B was harder than C (maybe that is wrong; I did not enter the round). So, I guess they decided to reverse their order.
Thank you for reminding me to set an alarm.
Hope this round will be great and problems will be interesting :)
At last, what is the score distribution?
Hope to reach Master for the first time :D
9:05am — 11:05 UTC (Codeforces)
12:00pm — 2:00pm UTC (ARC Div. 2)
LETS GO!!!!!
9:05am — 11:05 UTC (Im sleeping)
12:00pm — 2:00pm UTC (Im still sleeping)
LETS GO!!!!!
hope to cross 1350+)
trying to use gpt for problem C isn't a good way to cross 1350
I manage to solve A and B easily, sometimes C but sometimes it's difficult to solve C, can anyone tell what to do to solve C and D like any structured way or source to practice??
Follow TLE Eliminators level 3, spend time reading editorials (how do the makers build up to the solution ,).will help for sure.
but ye to free nhi hai koi free wala bta do if possible???
Ask Senior , CM sheet , and their solutions. Shayans' discussions on youtube (too few , but still better than nothing )
Cses problems set helped me lot. I don't practive anymore, but I solved first two sections and it made quite a difference.
Hoping that this is the last time ill be hoping to reach pupil.
Good Luck EVERYONE!!!
Wishing you a positive Delta!
🗿
huh?
🗿
🗿
🗿
Interested.
Only two div. 2 people tested?
This round feels kinda odd
Hope that Problem statements are simple as announcement...
..
Let's hope I dont spend the whole contest debuging just to later find out that a single character was wrong like Round 1030
glhf everyone.
Hope to cross 1700 this contest
Thank you for making such good and beautiful problems—I’m excited to see them. Yeahhh, lesssgo !! :)
I want to play maimai DX PRiSM PLUS after the contest.
Wow, find a player here.
Loved the Problems. Specially D ...
i submitted 2 solutions both are correct will i still get -50??
yep resubmission is penalised
the older one will get "skipped" verdict.
I'll give a shout-out to geometry on my suicide note
shouldn't have participated
What was that C !
You can find the empty cell which will destroy the least gold, then the place around the cell will be emptied and you can place TNT next to the former cell so that it won't destroy any other gold mine. It can be proven that after the first TNT is placed and the least gold is destroyed, the remaining gold can be all mined.
but checking for the next TNT(the adjacent cells) after placing each and every TNT would have given TLE.
You can check only one TNT. After checking it, other gold can all be collected.
For example,
You place the TNT on $$$(2,4)$$$, then it will be
Then if you place TNT on the cell next to the first cell like $$$(2,3)$$$, you won't destroy any other gold, and so on, you can collect all the gold remaining.
You dont need to. Once you made 1 explosion you'll never waste gold again because you can explode adjacent cells
u can just calculate the 1st position to DESTROY min number of golds. after that all remaining can be mined so directly return/print them as ans. no need to simulate further than step 1
Got it. Thanks
Apparently, 2D prefix sum. It took a good amount of time to figure that out. Lol.
1D prefix sum is fast enough though
Why do you think it is fast enough with 1D prefix sum?
I also used 1D prefix sum, because I did not have enough time, but I can't be sure that it will be fast enough in all cases.
The worst case would be 500x500 empty grid with k = 500, which is 500x500x500x2 = 125000000 row-prefix sums, which I guessed would be fast enough, and luckily was well within the limits. I didn't have certainty at the time of submission either, but I hadn't figured out the 2d way and figured it was worth a shot.
How to do D and F?
Problem D.
I used the method of binary search for answers. I binary search for the number of games that players can win. During the inspection process, I came up with a greedy method. Suppose we win $$$x$$$ games. I divide the array $$$a$$$ into two parts, the first $$$x$$$ and the last $$$n - x$$$. Then I will exchange the minimum value of the first half and the maximum value of the second half (of course, some special cases need to be judged, such as the minimum value of the first half being greater than the maximum value of the second half). This greedy train of thought passed the pretest.
It's a pity that I can't explain its correctness very well.
I had the same solution but somehow had some error ;-(
Ugh it was such a simple error too, fixed but too late :(
Apart from the extremely difficult D(Completely no idea), A and B were absolutely pain. These two problems need much more observation and mathematics details than usual, which makes them somehow very exhausting(at least for me).
I think that was the point.
D, I thought of Binary Search on the Answer method.
But actually I don't need binary search, I can brute force all answer from 0 to N.
Hope it passes the system test.
I also came up with the idea of binary search for answers. If my submission can pass the system test, this is the most amazing binary search answer question I have ever seen.
Game problem at this position is a little scaring. I guess D is not easy to get on with without some serious deductions or observation, but I didn't have time and energy to think more deeply after solving ABC.
Update: This is really a binary search problem. Amazing!
I like my non binary search solution more. :<
nahh bro, A and B were quite easy if u can visualise stuff.
how to solve C??
go on every empty cell and check what gold will be demolished if we detonated at that cell,subtract that from total gold in matrix as it will be always achievable after wards
so what I figured out was if you clear any square in the first move ... then you can always take all the remaining gold after that ( to prove this I drew a grid in my paper and then you can always expand the initial square one layer at a time in each direction )
so problem reduces to how many gold gets destroyed in first dynamite blast, and we would like to minimize this of course
so the problem is for the possible blast location in first move ( ie empty cells at center ) .. what blast square contains least amount of gold
this can be solved with prefix sum for 2d- grid like technique .. but you have to figure out rectangle affect by blasting at a particular location
Check which initial explosion will waste the least gold. After that, you can collect all the golds by choosing the empty cells optimally, so you don't need to check that.
Final answer is: total gold — least gold wasted from the first explosion among all possible first explosions.
Let's calculate the total gold of the initial matrix. The answer only depends on the first explosion we make. Let's try all the explosion we can make, and calculate the number of gold that is deleted after that explosion, let's denote it as x. Then the answer is maximum of all the total gold minus x over all explosion we made at the first move.
Problem F appeared before in BUET IUPC 2024
https://toph.co/arena?practice=672bc0ddd1fa3c8ceb98fa38#!/p/67238a8ea1980bf2ed626d61
It was weirder that the constraint was the same.
darnIt ....
problem C -> 20min
problem A -> 30 min ... 2 wrong submissions
Bhai the same thing is happening with me for the last 5-6 contest where i am unable to solve B but most of the time I can solve C in much lesser time.. Why is this happening?
Also can you tell what should I do to become specialist as soon as possible, i try to solve hard problems (1500-1600) and most of the time I am able to solve these in around an hour(unless its a dp problem), could you tell where I am going wrong?
I am sorry I have no specific response other than practice more..
but you have solved more questions than me.. so I don't think I qualify to give you advice on that as well LOL
In short skill issue right :p no worries I will keep trying as I enjoy it.
no of course not.. I have done lot of questions on other platforms.. it takes time... keep up the practice, but don't solve easy questions when you practice.. only questions which are around 100 to 300 above your rating.
B >>> C
Statements felt confusing.
GridForces :|
I hate Cheater. I hate cheater.
couldn't solve C, I know only brute force way but that is giving WA's, can anyone give idea in which direction we should think for such problems?
In this problem, at worst you'll only need to explode 1 crowded cell (might have gold in it), but after that you have room to move and you'll never lose any gold.
i checked the constraints ~500 so i thought of dp and dfs (graph theory in general) maybe 2d prefix arrays
thats why i got stuck i forgot 2d prefix solution can exist
As a participant who solved D but not B, C<A<D<B
Is it just me, or are the Div2 B's getting tougher day by day :(
someone can explain me: i didn't understand the D question 3rd test case
5 8 6 3 10 1 7 9 5 2 4
why i as a player can't swap 10 to 8 instead of 10 to 3 which is explained in ts.
if i swap 10 to 8, i collect more than 3 points.
swapping the max element to first card win you more game no ?
"Note that the game always lasts exactly n rounds."
i didnt think c can be solved using 2d prefix until the last 20 mins of the contest
trying dp and dfs was a headache
thank you for this beautiful contest!
.
I think it took me more time to figure out how the explosion is working in C than it took to actually solve it
same but i am still not able to figure it out, can you explain me?
basically, the top left will be (x — k — 1, y — k — 1), and bottom right will be (x + k — 1, y + k — 1)
I missed this contest due to some accidents, but now it seems that I am lucky
I envy you
I don't understand what I was doing wrong in qB
Maybe did not draw a lot of grids.
LOL..
Terrible statements and testcase examples for C, very unclear and not explained properly.
i think they only missed mentioning its infinite explosions, but explained later in the notes
wtf, kya hi contest tha majjaaa aagyaaa :)
Please someone share idea to solve D,
I couldn't solve it during the contest and didn't get any ideas on how to tackle it.
In problem D, is it true that if the maximum of $$$\min(a_1, a_2, ..., a_k)$$$ after swapping is larger than $$$\min(b_1, b_2, ..., b_{n-k+1})$$$, then I can win at least $$$k$$$ times? I tried this but got wrong answer.
The idea seems correct (though I haven't performed an extensive fuzzing). However, here's an example of a test that breaks your solution:
I don't know what's wrong here — supposedly the way you find the best swapping is wrong.
it has to be right? you're playing n rounds, so n cards got discarded. the one that remains has to be the one with the minimum value amongst all the n+1 cards you mentioned.
I could make no observation for A problem. what was it?? B felt far more logical than A (i hope sys test don't prove me wrong)
For A ... what I finally figured out was that try to reduce by minimum delta.. so if
x < y... use allxmoves first until possible .. else use allymoves firstthen use the remaining moves .. but I made wrong submissions before figuring this out.
implementation , Take from the cheaper option until you can’t anymore, then try the other one. use an equation to bypass time limit
AM I THE ONLY ONE WHO FELT PROBLEM B WAS MORE TOUGHER THAN THE USUAL DIV 2 B PROBLEMS?
yeah although the code was very less, it took some time to think :( .. I figured out C faster
Still easier than the permutation-related B from the previous Div 2.
That problem was much easier than this one
No doubt that this round required more time, especially in testing and improving problems, so tough problems that seem to include tons of corner cases
problems were good.
anandxaditya was in my room and I'm pretty sure he has cheated. Just look at the quality of documentation he is doing while maintaining his speed
documentationha ha!!!Yeah, considering there's literally a
# In compliance with your request, this code is functionally correct but intentionally obfuscated to be unique.in the code on the THIRD LINE, that's probably the first time ever I can agree a solution was autogenerated.LOL, this is very funny to leave such a comment.
that dude submitted 60 code for 1 contest, absolute cinema.
absolute cinema..... ROFL
In compliance with your request, this code is functionally correct but intentionally obfuscated to be unique.
Main execution loop to handle multiple test cases with obfuscated logic.
324510696
Along with the sudden change of the language.
wow... LOL
How to Solve B ?
I figured by drawing some grids on paper
we can solve it in each dimension independently
so find
hGapandvGap... horizontal and vertical gapit is possible to fill the gap between them if it is divisible by
length in that direction... I didn't prove it but I was not able to fill the grid when it was not divisiblealso these gaps should be >=0 ... i think -ve can give you wrong answer like
-2is divisible by2.. but that doesn't countI also did the same like the gap in vertical direction will be abs(max(y1,y2)-(min(y1,y2)+b)) right?
yes, that is what I did to find the gap.
Unusually difficult contest. B and especially C were ridiculous compared to most other div2 contests. D in contrast was unusually easy (though proving the solution, less easy).
Oh wait, there was only one div2 tester, that's why :smile:
please tell the idea of D... I was not able to make any progress on it.
binary search on the answer, to test whether K <= answer play out the game with
either the initial layout
or (if K < N) with a layout where the smallest number from the first K is swapped for the greatest number from the last N-K (oops it said K which is a typo)
each playthrough is O(N), finding the elements to swap is O(N) (though can be faster but it is unnecessary), O(log N) attempts to find the answer => N log N
oh I see, thanks very much for sharing the idea.
OK so the direction to pursue was
given a score, can I achieve it with at max one swap.. then binary search on the scorehow did u come up with that conclusion of first k and last k if its so difficult to prove?Isn't it kind of random
not last k, last N-k — was a typo :( basically last N-k is the cards that do not play if you win k rounds, and the owner of the smallest card loses, so you want to push the smallest item far away so it does not play.
Can someone explain the approach for problem B?
my idea
https://codeforces.me/blog/entry/143739?#comment-1284121
How to solve problems like C and D.
in C just first time explodes cost gold, rest all can be collected.
why this works?
because u can do the next explosion on some cell adjacent to the last explosions's center and it will collect the gold just outside the last explosions's border, and no extra gold is wasted since u already collected gold from last explosion's border. keep repeating till all cells are covered.
can you please elaborate and why does it work like that
Once matrix get explode, then you can collect all gold consecutive side(in any direction) and by similar way you collect all other gold, hence no loss of gold happen.
Can anyone share the core idea for D? I solved F after C, but have made 0% progress on D since then :(((
quick editorial is already out, so we can read the official answer...
ty, I didn't expect it to be so quick so I didn't check >_<
yes it is indeed very quick. thanks to authors.
My idea for D is quite the same as official solution.
The Idea: If you want to get x score then all your (first x) cards must be greater than the smallest (first [n-x]) cards of enemy.
The main difference is I iteratively check answer from small to big (big to small might be better),
While the official solution uses Binary Search.
Edit: wrong explanation
nice idea, you woke me up with just one sentence D:
trash mathforces + gridforces + guessingforces.
trash round
MikeMirzayanov, vaaven the account yashhatwar is suspicious. Have a look at these submissions from today's contest: Seems from some LLM: 324492128, 324511691 Looks original: 324481085
These submissions from round 2117: Seems from some LLM: 323469770 Looks original: 323455468, 323437423
Did the authors think B was easy just because the solution is so short? How absurd! There should've been testers of lower ratings as well
even q1 was bad :(, i got a +2 on it
If C can be solved in O(n^2) using 2D prefix sum, why was limit on
nkept <= 500?It's funny.
Many people complain that the contest is difficult, pointless, and the questions aren't tested. Is there a chance it will be unrated?
I think there is some issue with the ratings awarded in the contest. I solved 2 ques and got rank 4200 but still there was only +1 increase in my rating.
Less folks gave this contest, the odd timing probably trimmed of a good portion of skilled participants
Not a proper Div. 2
agree
B is so trash... 2 hours of hard brainstorm and zero as result
shitty contest
Hello coordinators,
I received a plagiarism warning regarding my submission (ID: 324506450) for problem 2113C, stating that it significantly coincides with other solutions.
I would like to respectfully clarify that I wrote my code entirely by myself during the contest. I used the CodeChef IDE to write my solution and was not aware that it might be publicly accessible. I did not share my code with anyone, nor did I copy from any external source.
I’m genuinely surprised by this warning, as I took care to participate fairly and independently. If a similarity exists, it must be purely coincidental or unintentionally caused by the editor I used.
This is the first time something like this has happened to me, and I now understand the importance of using private local editors. From now on, I will make sure to use a local editor like Visual Studio Code to avoid any such issues.
Please let me know if I can provide any further details to support my case. I would be grateful if you could kindly review the situation again.
Happy to explain my solution or share additional information if required.
Thank you for your consideration.
awful
I received a message that my solution (ID: 324490202) for problem 2113B significantly coincides with submissions from other users. I would like to clarify that I wrote the solution entirely on my own during the contest and did not engage in any form of cheating or code sharing.
I have not shared my code with anyone, nor have I copied from any source. If there is any similarity, it is purely coincidental or possibly due to similar logic being used for standard approaches. I did not use any public IDE or make my code accessible online in any form.
I fully respect the rules of Codeforces and competitive programming ethics. I kindly request a fair re-evaluation of my submission.
Thank you.
Competitive Programming in 2025 – A Broken Race?
Two coders. Same leaderboard.
Result?
The problem: CP is turning into a “pay-to-win” model.
Impact:
The spirit of CP is at risk !!
The ask: Platforms like Codeforces, CodeChef, LeetCode must act fast. Cheating isn’t just breaking rules — it's breaking the community.
Let’s keep CP clean. Let’s keep it fair. Agree or disagree?