Привет, Codeforces! 👋👋👋
Во Jun/17/2025 17:35 (Moscow time) начнётся Codeforces Round 1032 (Div. 3) — очередной Codeforces раунд для третьего дивизиона. В этом раунде будет 8 задач, которые подобраны по сложности так, чтобы составить интересное соревнование для участников с рейтингом до 1600. Однако все желающие, чей рейтинг 1600 и выше могут зарегистрироваться на раунд вне конкурса.
Раунд пройдет по правилам образовательных раундов. Таким образом, во время раунда задачи будут тестироваться на предварительных тестах, а после раунда будет 12-ти часовая фаза открытых взломов, после её завершения все успешные попытки будут перетестированы на успешных взломах. Я постарался сделать приличные тесты — так же как и вы, буду расстроен, если у многих будут падать решения после окончания контеста.
Вам будет предложено 2 часа 15 минут на решение задач.
Штраф за неверную попытку в этом раунде будет равняться 10 минутам.
Напоминаем, что в таблицу официальных результатов попадут только достоверные участники третьего дивизиона. Как написано по ссылке — это вынужденная мера для борьбы с неспортивным поведением. Для квалификации в качестве достоверного участника третьего дивизиона надо:
- принять участие не менее чем в пяти рейтинговых раундах (и решить в каждом из них хотя бы одну задачу)
- не иметь в рейтинге точку 1900 или выше.
Независимо от того являетесь вы достоверными участниками третьего дивизиона или нет, если ваш рейтинг менее 1600, то раунд для вас будет рейтинговым.
Хочется выразить слова благодарности:
Vladosiya за прекрасную координацию раунда.
Sugar_fan за красное тестирование раунда.
cry, Friendiks, EzikBro, Ste за оранжевое тестирование раунда.
Egorov_Dmitriy, katzi, KotlechkovEgor за фиолетовое тестирование раунда.
Chugunov_Alexander, itz_pabloo, IceHydra, NicoRobin, OutrunMyGun, gbula за синее тестирование раунда.
_supersonic_, ne_justlm за бирюзовое тестирование раунда.
MikeMirzayanov за системы Polygon и Codeforces.
Всем удачи! 🔥🔥🔥









hoping to get positive delta!!! (from a warrior race)
Hope to reach Specialist And complete my goal one month earlier In the bottom of the table....
Same) Btw I am there too
Hope this will be a great round :XD
ROAD TO EXPERT!!
Only two div. 3 people tested?
Don’t worry it is probably ok because the non div 3 people were div 3 once too (probably)
hope to reach $$${\color{green}{pupil}}$$$
$$${\color{cyan}{and}}$$$ $$${\color{orange}{good}}$$$ $$${\color{red}{luck}}$$$ $$${\color{purple}{everyone}}$$$ $$${\color{blue}{!!!}}$$$
P.S: not today :(
hoping to get positive delta!!! (Recover from last Div 2):)
haha, check my prev div 2
rise again fall again , better rise again !!!
Hoping to reach a specialist in this contest.
same
Hoping to keep a specialist in this contest.
1401 is so danger lol
Hoping to solve 5 questions for the first time.
Score distribution?!?!?
1-1-1-1-1-1-1-1
i hope it goes well
Omg finally my first unrated div3
Hope to become div 3 unrated in this contest
hope to reach pupil
As a tester, I wish you all good results on this great round!
Hoping to reach pupil this time
good luck everyone
I just want 5 AC in this contest.
expect to expert
The internet in Iran is terrible due to the conditions I hope I don't have any problems posting.
When I tried to upload my solution to the 3rd problem I got a "Sorry, you have been blocked" message. I tried and it is now blocking sending in solutions for previous competitions too. I tried to find info on the "help" page, but nothing useful. Anyone know whom to write to, and/or why this would happen?
Contest with perfect level wise problem
Good contest, had fun!!
how to solve D
Use bubble sort , one thing i found more useful is
normally we say that bubble sort takes n^2 time complexity but in real it takes max (n)*(n+1)/2 in question n was max 40 so for the both the arrays this will pass
initial i thought that 2 (for both array )* n^2 (i assumed that bubble sort is n^2) operation will need and i was confuse to solve it later i realized bubble sort requires less then n^2 operation
it is very very good problem , you can check my submission
did anyone else do a randomized solution for $$$E$$$?
such a boring and uninspiring round. i felt like i was doing a codechef round smh. had the solution for F just couldn't be bothered to write it. i really dont know how any problems from C-F were accepted as actual problems, really disappointing
HOW TO SOLVE C?
Beautiful problem H!
Was it just me or was C more difficult than D and E...
for me D is harder than E F G H
why? I thought it was pretty easy to guess bubble sort would work operation wouldnt exceed 1709
yeah d was just bubble sort
nah top 100 div 3 in this contest, 70 cheaters, 30 smurfs
I think I won't be able to participate in the codeforces contest until further notice The internet speed here is terrible and it takes 5 minutes to get to any page (due to the war) Goodbye codeforces!
nah top 100 div 3 of this contest, 70 cheaters, 30 smurfs
Can E be solved without Dp If not can u explain the DP solution Much love yall
hope all AI-cheaters will get banned
Couldn't figure out why this fails on test2 in F: https://codeforces.me/contest/2121/submission/324900759
Mine too is failing:
https://codeforces.me/contest/2121/submission/324969264
Idea is it maintain a inverted fenwick tree on max as I iterate from left to right.
And then do binary search over indices.
Is there a solution to E without dp ? If so please explain it If not can u explain the dp solution
Not sure what the dp solution is. I did it as follows:
Start comparing digits of l and r from most significant to least significant and find the longest common prefix. The number x will need to have the same digits here. If the length of this common prefix is p, then 2*p is added to ans.
Now for 1st mismatch in digits of l and r, if digit.r > digit.l + 1, then we can construct x with no more common digits to l and r. In this case 2*p is the final ans.
Otherwise, there are 2 cases:
So ans = 2*p + min(q+1, r+1)
A purely greedy / constructive solution in O(number of digits): 324911040.
I solved it without dp It wasn't a hard problem but there were a lot of small points! I hope this code helps you:
n is the number of digits and res1, res2 are the input numbers that I received as strings
see my Solution Purely Greedy we st
Here is my solution using DP. I am not sure if it is optimized properly, but it got accepted.
The goal is to minimize:
f(l, x) + f(x, r)We solve this using digit DP. The DP state tracks:
xrelative tolandrDP State Definition
dp[i][d][s]: Minimum matches wheni: Current digit position (from most to least significant)d: Digit placed at positionis: Current state ofx:0: Equal tolonly1: Equal toronly2: Equal to bothlandr3: Strictly betweenlandrBase Case
At the most significant digit
p:l[p] == r[p], we initializedp[p][l[p]][2] = 2l[p] != r[p], we initialize:dp[p][l[p]][0] = 1dp[p][r[p]][1] = 1(l[p] + 1, r[p] - 1), setdp[p][d][3] = 0Transitions
Loop from position
i = p-1down to0, and try all digit/state transitions:From state
0(equal tolonly):0if current digit isl[i](add+1)3if digit> l[i](add+0or+1if digit also equalsr[i])From state
1(equal toronly):1if digit isr[i](add+1)3if digit< r[i](add+0or+1if digit also equalsl[i])From state
2(equal to bothlandr):l[i] == r[i], stay in2and add+20if digit isl[i](add+1)1if digit isr[i](add+1)3if digit is between (add+0)From state
3(strictly between):+1if digit matchesl[i]orr[i]Final Answer
Minimum of all values
dp[0][d][s]over all digitsdand statessImplementation Code: 324944536
Problem G : codechef
this is actually crazy, might be the worst div3 i ever participated in
Had a lot of fun with problems F, G, and H. Thank you!
On a separate note, my solution to H was with lazy segment tree. Could somebody please tell me a cleaner idea? And, apart from that, my G uses three segment trees (well, four to be precise, but that was because I went crazy there for a sec), so a cleaner idea would also be appreciated.
I did G as follows:
Define a function g(l, r) as the minimum of frequency of 0 and 1 in s[l...r]
f(l, r) + g(l, r) = r-l+1 It is easy to find summation of f(l, r) $$$-$$$ g(l, r) over all (l, r). For the given string, keep a prefix array p with p[i] = number of 0's in s[1...i] $$$-$$$ number of 1's in s[1...i].
f(l, r) $$$-$$$ g(l, r) = abs(p[r] $$$-$$$ p[l-1]).
The rest is just computing sum of abs(p[x] $$$-$$$ p[y]) over all (x, y) which can be done by sorting p.
For problem H: You can extend standard LIS algorithm for this question whose implementation is very simple (just 3-5 lines of code using multiset).
Submission link: https://codeforces.me/contest/2121/submission/324947588
Great
I have a small doubt in understanding the problem statement, for k=2 do we need to consider just {a1,a2} or {{a1,a2},{a2,a3}....} set of all subarrays of length 2 ?
We only need to consider prefix of original array for each k. If k = 3 then consider only one subarray [a1, a2, a3].
I have a divide and conquer solution for G
max(a,b) = (a + b + |a - b|) / 2, now a + b is length and |a - b| is absoulte sum of diff in ones and zeros, now to calculate for every subarray, lets use divide and conquer, partition by mid and now we need some O(n) or O(nlogn) solution to calculate the abs sum of diff of those subarrays whose right end point lies from (mid + 1 , r) and left endpoint lies from (l,mid) which is easy to calculate since you can sort the diff array from l,mid and find prefix sum over that, code should make it more clearMy solution was fully inspired by yours — I learned a lot just by trying to understand it.
But I didn’t fully understand what’s actually going on in the divide and conquer part.
But, but, but... I think I’ve come up with a version that’s better — or at least easier to understand !
You used this formula:
That gave me an idea — why not just start by adding the total sum of all possible substring lengths, which is:
Then I realized, we just need to add the sum of all absolute differences of the prefix balances, which reminded me of a classic LeetCode problem —
“Sum of Absolute Differences in a Sorted Array.”
So even though I didn’t directly understand your approach, the idea you shared still helped guide me in the right direction. Thanks for that!
Here’s my code: 325253633
I bricked problem F with sparse table and binary search... Turns out I don't have enough time sadly.
For problem F, can someone explain why am I getting TLE with this code though I used binary search?
vll &vec = mp[need];
This is the only change you need to do, you need to access vector by reference, otherwise it will take O(size of vector) time to access the vector from the map, using &, you can do it in O(1).
why does this approach for F not work? what to change in this to make it work? Submission
You brute forced over all candidates, which is $$$O(n^2\log(n))$$$. You could use binary search to reach $$$O(n\log^2(n))$$$.
Problem G was nice!!!
The first div 3 contest that went good : )
me solving F be like I need sparse matrix no wait there is no need.no wait I need it,ohh yeah it can be done without spare table
exactly same here, wasted a bunch of time because of lacking experience.
It can be solved by sparse table or without one also can. I've done both but... after contest))
why the contest rating have not made any changes in already existing rating of mine? is the issue with someone else as well, it is not even showing in the graph as well
you have to wait for the system testing to finalize the rankings then it will be reflected on your account
Some of these cooked me ~
Can anyone help me with C ?
The idea is this: consider the maximum value in the grid, call it $$$X$$$, and look at all of the cells which have value $$$X$$$. If it is possible to choose a row and column that encapsulate all of these cells, then that becomes the optimal choice and the answer is $$$X - 1$$$. Otherwise, the answer is $$$X$$$.
There are a few ways to do this; the important part is NOT writing a $$$O(N^2M)$$$ or $$$O(NM^2)$$$ solution. If you do, you'll TLE to test cases with large $$$N$$$ or $$$M$$$, respectively.
My solution takes advantage of one property: assume that we can encapsulate all of the cells containing the value $$$X$$$. Pick any one of these cells (it doesn't matter which) — we will have to use either its row or column in the optimal choice. Assume we use its row; consider the set of cells with value X not on this row. If they all belong on the same column, it works. Otherwise, it doesn't. Swap the rows and the columns for the other case. Since there are at most $$$NM$$$ cells containing the maximum value X, this solution runs in $$$O(NM)$$$ time. You can check my solution for implementation.
You can actually pass an O(NM*min(N,M)) solution because of the constraints. Here's my submission
https://codeforces.me/contest/2121/submission/324849659
True, $$$NMmin(N,M)$$$ is no more than 1e5 ^ 1.5 so it will pass
Pretest case should be more strong enough for problem C.
Hi Folks,
This is my first contest ever and at the moment I am unrated. I solved 6 out of the 8 questions in this round. Can I expect some kind of rating after this?
Thanks
Na , u can not expect
you'll be receiving a penalty because you cheated during this round using AI... really well done dude
Such a nice contest it was in terms of the problems given. Hopefully, I also got what I aimed for.
hoping to get positive delta!!!
My pF got hacked (unordered map) QAO
here after long time , has cf changed something? i am not able to view other code for submissions.
You still can; just go to the leaderboard, find a user's row, then Ctrl + click on a cell in that row to see the results. From there, you can click once more to find the original submissions.
I think the two hacks I made on C were test cases 9 and 10... and holy moly so many people got TLE on 10. I'll take it :)
when is the editorial coming?
its already up. Dont know why the author hasn't given the link, but this https://codeforces.me/blog/entry/143822 it the editorial.
voventa why no thanks to 74TrAkToR?
when will we get tutorials?
when will we get the tutorials?
tutorial posted here
ok thanks
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?
Простите за не доумение я сам в шоке что получились такие совпадение но Najibullo_prog это хейтер он создал аккаунт из моего имени не знаю что он что то решал но я сам в почти последних минут решал эту задачу думал эту будет не челевечно если мне даст большой минус и блок всех задач иза одних совподений а NAZIROV я сним знаком он решил задачу сам и бысрее чем я тоже решил после него. простите за недоумение я иза совподений вообще изменил стиль писание кода
Appeal for "My solution 324842333 for the problem 2121C significantly coincides with solutions of 1 Other", I was quite surprised and shocked seeing the mail, totally unexpected. I had submitted my code at 8:45 (IST) and then continued to code with my other problems and finishing the final one at about 10:07 (IST), All my solutions have a laid out consistent writing style, with significant inspiration from youtube tutorials and video lessons. I still can't figure out how my this other person, who submitted the problem about more than an hour later, got it same as mine, even though his solution looks like it's been directly off GPT. Please take a look at it and provide a solution. Thank you for your time and understanding.
324828250
D ,1709... I wanna what is the 1709 meaning;I am just interested in that