Hi, Codeforces!
I'm delighted to invite you to the best/second best/third best round of 2025 so far! Codeforces Round 997 (Div. 2) will be held on Jan/17/2025 17:35 (Moscow time). You will be presented with at least $$$6$$$ and at most $$$6$$$ problems, one of which might be divided into two subtasks, and $$$2$$$ hours to solve them.
Many of you may not believe it, but the problems were authored and written by nifeshe with a great help from maomao90. Moreover, I would like to thank:
maomao90 for coordinating the round and helping with tasks ideas/preparation.
Alexdat2000 for translating the problems to Russian.
All of our testers: errorgorn, A_G, LipArcanjo, _istil, Markadiusz, Error_Yuan, Intellegent, mwen, Friedrich, flammifer, iLoveIOI, Rideris, DilshodbekX, chromate00, tibinyte2006 for, believe it or not, testing.
MikeMirzayanov for the Codeforces and Polygon platforms.
Bliznetc for playing chess with me.
And You for participating!
The score distribution is as follows: $$$500-1250-1500-2000-2250-(2750+1250)$$$.
I hope you will find a non-empty subset of problems to be interesting. Good luck!
UPD 1: Editorial
UPD 2: Congratulations to the top 5!
Div. 1 + 2:
Div. 2:
UPD 3: First solves:
A. 00:02:01 by hitonanode
B. 00:02:17 by pipi0818
C. 00:03:52 by Proof_by_QED
D. 00:13:53 by wishgoodluck
E. 00:18:06 by zdc123456
F1. 00:27:48 by peti1234
F2. 00:28:40 by rainboy









According to the score distribution, it seems a bit easier than last div2 Round ?!
It's not related .
WOO , I haven't known that yet.I have just supposed this score is equal to difficulty (
no it's not , as cry pointed out in his own blog here
thanks for link;
👍
So now the LGM tag isn't even good enough for the "And You for participating!" line. They've trampled all over the meaning of the word legendary.
Believe it or not, I tested.
I'll test it tomorrow, live during contest
As a participant, i will try to solve A within 5 minutes.
i believe in you
Pressure++
lets do it!!
what about B and C??
B before 20 and C before 60 (And D if I can).
Nike:Just Do It.
IM...wow!!
As a cheater who got her first contest skipped, I will try to cheat my way to Pupil in this round
But why u solved C only?? Didn't u got solutions of A or B?
I read many blogs after contest skips which mostly say they got skipped because their codes were short and common so I didn't copy A or B because the ones I found on youtube and telegram were very small like 10-12 lines only
Cheating with prepration.Crazy
lmaao you call it preparation? My classmates took an entire course worth 3000 PKR which trains them on how to avoid plag while copying codes from telegram/youtube. They also give them resources to cheat like names of telegram channels, websites and even contacts of people who sell it at cheap rates (for problems E or F of Div 2. Upto D are mostly free. Paid only if you need D in less than 1 hour). They also give plag detector links where you copy paste both source code and your code and it tells you percentage overlap. Live contest doubt support is also provided like if you get WA after changing they tell you why it gave WA rather than giving solution to make you independent for future contests. They also have mock contests where you are given answer code and you have to change it during contest and then they are run through plag checkers to see if they match. My brother himself prepares 8 hours a day from that course but my parents didn't spend money for me because I am a girl and they don't want me to get a job. But what you call cheating isn't a noob's thing this also requires efforts and learning it is a science of its own if you want to learn how to change codes quick and bypass plag checker and test your code for plag live contest. I just try to learn as much as I can by seeing them. But that group has given some Candidate Masters (one from our country too) and Masters too. But not everyone gets there unplagged only the most efficient people do. Many get caught and get banned as Pupils/Newbies and many cant understand code enough to change it beyond A.
:)
speechless -_-
maybe instead of cheating just learn how to code its not that hard
We have the same picture :)
maybe we have stolen this picture from the same person
Hope we can have easier E and F to solve. E and F for last Div.2 are not fit for rated participant(but it has nothing to do with me thinking they are good problems, especially E is interesting), only two can solve E and no one can solve F is abnormal.
It seems like that E is much more friendly but F2 still hard.
what is the contest duration
Updated the blog
Hoping for the contest to have >2 solves on E, F! (oops)
B seems harder than usual
If I don't become specialist in this contest then I'll
try again in the next one
good luck
1000 problem solved wow! why dont u start solving higher rating problems tho?
Currently I'm learning various topics and practicing on others platforms and solving problems topic wisely..
I think it will be interesting round !
Mashaa allah on ur profile salah, i have no idea what will happen tommorow but i know that you put a lot of effort, best of luck.
Thanks <3
This has probably been answered before, but why not have all the rounds on weekends? Americans can not compete in standard-time weekday contests.
If you can't even compete in standard-time weekday contests, are you even free?
Like the last contest, I don't want to mess up this one either. :)
B>>C ?:(
"You will be presented with at least 6 and at most 6 problems" interesting description.
КЛЯНУСЬ МАМОЙ ВОЗЬМЦ ЦИАНА
As a participant, I will try to beat rainboy ;)
That is on problem F to decide
Guys I think there are 6 problems
You got it wrong bro... There will be at least 6 and at most 6 problems.
What will be a 1250 score div2b like be?
Since score is relative to previous problems, I think problem A will be more easier as B is 1250 scored...
I just want to break the curse of problem c. I'll definitely solve it this time ^.^
I solved C but couldn't solve B. My day is ruined
B was harder than C or they were equal imo.Starting with C was good option
nvm I reached my goal
You will be presented with at least 6 and at most 6 problems.
But what i can do is 0
will be ending myself if i cant solve D.
how many question i have to perform for becoming specialist?
This depends totally on Round.. But I guess 3 Problems would be a safe number for you. If the contest is easier, speed matters..
I will solve at least 0 problems and at most 6 problems.
I wish you success! :D
Hoping I could get into 1600++ :D
Serious disappointment after waiting for a week.
insane gap from c to d
wtf diff gap A *900 B *1400 C *1500 D *2200
C is 1200(MAX)
B > C
Why continue to make problems like C,it serves no purpose, extremely disappointed by the quality of problems.
first 56 minutes: Solve Problems
last 1 hour 4 minutes: stare at standings 💀
Same :((((
B >>>>> C, the order of B and C should be swapped. Who started with C will very likely to win a lot of rating in this contest
Also I have absolutely no idea how to solve D sadly. (last div2D was way better tbh)
Am I the only idiot that can't even figure out what B is asking. I swear the diagram they've given is wrong but maybe I'm just dumb.
problem C is such a piece of shit
why this allowed?
ConstructiveForces
Problems were pretty difficult but also really nice.
Thanks for the great contest!
This is (in my opinion) one of the best div2 rounds I have ever participated in. Thank you for the brilliant problems. I enjoyed every problem (except B). Ran out of time in F2 after getting the main observation in last 10minutes :(
For you
See difficultly gap between C -> D. It was one of worst time trial for div2. how to solve ABC fast, depending on time it can be gray or orange
chill
enjoy the problems. Quality is much more important than any difficulty imbalance (and before you say I am saying this only because I am too high rated for div2, I really like AGCs despite solving 0-1 problems)
difficulty gap hardly matters in the long run (unless you secretly believe that everyone wants you to always suffer and gives only your rating the big difficulty gap each time)
Agreed for A and D. D especially is a very nice problem.
Though B and C, the language for them was pretty bad. Spent more time reading the Q than thinking about the problems. Those two could have been way better phrased imo.
FastForces intensifies and C << A << B
I couldn't solve D, but it was an amazing problem imo.
thank you for contest!! D was good problem. However, I am not too sure about the point of question C
I think graph was introduced in problem B just to scare the participants.
I got scared while the contest I thought dfs is the method to used
6000 solved C, 500 solved D nice complexity management!
it's actually 8500
E seems way easier without the equality in the 2nd condition. How to solve with the condition having $$$\leq$$$?
What a big gap bitween C & D!
jaja bit-tween, that was good
Can someone tell me which test case my code failed in B. https://mirror.codeforces.com/contest/2056/submission/301455594
I thought I would solve at least 3 problems. I was really sure that C will give me hard time but well life can be very surprising sometimes.
t=1 n=3 000 001 010 Correct answer: 2 3 1. Your answer: 3 2 1. I didn't quite understand your idea, but it seems that it's just wrong
actuallyl it is an adjacency matrix so your input is fundamentally wrong. In undirected graph the matrix is symmetric
I implied this input, it's just that I didn't know how to markup my comment prior
Oh I misunderstood. I think I got the problem in my approach. Actually my idea was to start with the minimum element that is 1 and than see how many elements it is connected to which are more than it.
Than I take the total number of these elements, subtract it by n and that is the position of 1. But I didn't implement the caculation process of subsequent elements correctly and that's where my downfall lay...
Anyway thank you for your testing it helped me to understand problem in my code that has been bugging me for a while now.
Have a great day/night.
Any idea which test case is failing for my submission: 301434979 for Problem B. I used a bubble-sort-like approach.
Can anyone tell me what's wrong in my code?
Try this input:
hate speedforces and B ate all my damn time. 5 more minutes and could've done C whatever looking forward to better weekend contests
not even in my dreams would i expect seeing graphs in a div. 2 B lol
u dont need knowledge pf graphs to solve it, they just used them to write the question in a different way .
In problem C why we cannot do
then f(a) = n, g(a) = 1, which is failed the problem condition g(a) > n
thanks everyone I understood now!
In problem D, I came up with the following conditions for subarrays with even length $$$l$$$ and median is $$$m$$$:
If $$$x$$$ is number of elements $$$ \lt m$$$ and $$$y$$$ is number of elements $$$ \gt m$$$, then $$$l-2x \geq 2$$$ and $$$l-2y \geq 2$$$.
Following this observation, $$$O(10n^2)$$$ solution is obvious to me. How can this be improved to $$$O(10n \log n)$$$? I was trying some $$$\texttt{ordered_set}$$$ and $$$\texttt{order_of_key()}$$$ stuff but could not come up with the solution. Can anyone help me with it? Here is my submission link.
using inclusion-exclusion principle.
Same here :-(
For a particular subarray [l,r] we can say that it is bad if either of these 2 conditions are true l-2x<=0 & l-2y<=0. Both of these can't be true simultaneously unless m isn't present in that subarray.
Thanks a lot, I got AC now. If anyone wants to see
Problem B was cool as it is the definition of topological sorting
lol
There was a problem with the checker of problem C. WA here AC here . Codes are same but specifically for only the third testcase it showed WA if i did not print a gap after the last integer(i printed newline). also F(a) would be 3 but the checker showed 5. hence the checker must be incorrect and i incurred a lot of extra penalty
Consider spending more time thinking before claiming the checker is wrong.
There is a difference between
else ifandelse, for n=6 your first code is outputting two sequences.oh crap my bad
Can someone give hints for D:))
Problem C literally writes the answer for $$$n\ge 9$$$, and I don't know if it is intended.
It literally writes the answer for all $$$n$$$ lol.
My AC solution is just:
The intuition is that each element added in (2) increases the number of palindromes with the first two "1" by exactly 1, so it will always be $$$\gt n$$$.
Now if only I could have figured this out before coming up with a general solution for $$$n \gt 9$$$ and individual hard coded cases for $$$6 \leq n \leq 9$$$ T_T
My AC solution is:
I just print 1 1 2 3 4 ... (n — 2) 1 (palindromes are in the format 1 ? 1). This solution does not work with n < 6.
My solution is directly derived from the first sample. The following sequence:
satisfies the problem's condition, because $$$f(a) = 3$$$ and there are sufficiently many palindromic subsequences of length $$$3$$$.
I really doubted myself when I found this, and I had to repeatedly check it...
Problem A was harder than problem C.
My solution for B is literally just a simple sort function, I don't know why it's considered to be "much" harder than A lol. Personally, I spent a little more time on A than B.
can you share your solution???
Feeling the distinction of difficulty levels in the last two contests kinda frustrating. Each problem is cool when viewed individually, but together in a single contest, they don't form a reasonable difficulty gradient.
Btw, I thought getting the answer for $$$n\geq9$$$ directly from the sample is the intended solution for C. It's interesting to see it's not
Is this the intended solution to D? Or is there an easier approach?
Notice that a given range [l + 1, r] is not good if either of the following are true:
where $$$\text{prefix_lt}$$$ and $$$\text{prefix_gt}$$$ represent the prefix sum of numbers less than and greater than $$$m$$$ respectively.
This can be re-written as:
Notice that the two conditions are mutually exclusive, so you can just subtract these two counts separately:
$$$r - \text{cnt_prefix_lt_upto}(2 \cdot \text{prefix_lt}_{r} - r) - \text{cnt_prefix_gt_upto}(2 \cdot \text{prefix_gt}_{r} - r)$$$
(except for the case where the median value isn't present in the subarray, lets ignore that since I ran out of time trying to fix that, we will likely have to store the "l" values till we see an $$$m$$$ after it)
$$$\text{cnt_prefix_lt_upto}$$$ / $$$\text{cnt_prefix_gt_upto}$$$ can be fairly directly implemented with a Fenwick Tree (bit).
So this feels way too overcomplicated for a problem D to me, am I missing an easier solution or is my brain just fried today?
you can solve it by doing the -1/+1 trick for medians + a sprinkle of PIE.
I dont think they are mutually exclusive, they may each equal exactly half?
We can calculate by inclusion-exclusion principle: Let b be any subarray of a of even length, cnt[i] = # of occurences of i in b. b is not good iff there exists some j, such that cnt[1]+cnt[2]+...+cnt[j] = |b|/2.
My $$$D$$$ solution:
First, we notice that
maxais quite small, which inspires us to enumerate the median.Suppose we determine the median $$$m$$$ and only count the even-length subarrays. The subarrays we are looking for must satisfy the following conditions:
It seems difficult to count the subarrays directly based on these conditions. We transform this problem by considering the subarrays that do not satisfy the conditions:
This makes it easier to count. Next, we explain how to count the subarrays where the number of elements less than $$$m$$$ is greater than or equal to half the length of the subarray.
Let the array be $$$v$$$. If $$$a[i] \lt x$$$, set $$$v[i]$$$ to 1; otherwise, set $$$v[i]$$$ to -1. Then, calculate the prefix sum array $$$pre[i]$$$. This allows us to find the number of indices $$$j$$$ such that $$$pre[j] \leq pre[i]$$$ using a binary indexed tree (BIT).
We also need to ensure that the subarray contains at least one $$$m$$$, which can be maintained by using a waiting area
wait. When calculating the prefix sum $$$pre[i]$$$, we do not immediately insert it into the BIT but instead place it in thewaitarea. Once we encounter a new $$$a[i] = m$$$, we insert the information fromwaitinto the BIT and clear thewaitarea.Is it a speed typing contest, like three digit rank after solving three questions and also 8k rank after solving three questions ( ╹▽╹ )ʘ‿ʘ
yeah but usually higher rated people got better ranks so nothing changed.(I reached my goal finally)
Lost D because of an extra unnecessary assert :(
In 3rd question all pretests passed but in the final checking it was not checked and was neither accepted nor failed in any test , I expect this as a glitch in the website , kindly look into this and help to get the correct standing .
My C solution 1 1 2 3 .....n-2 1 Here g(a) = 2n-5 which will work for all n>5
D is an amazing problem!!
For a subarray $$$b$$$, let
cntdenote the counter of the elements in $$$b$$$. In this problem the length ofcntwill be at most $$$10$$$.If $$$b$$$ is not good, then $$$a$$$ has an even length $$$L$$$, and also $$$\frac{L}{2}$$$ will have to appear in
acc, whereaccis the presum ofcnt. Obviously for $$$b$$$, only the frequency array $$$cnt$$$ matters.Consider enumerate the median $$$k$$$ seperately.
Consider the subarray $$$b=a[j...i]$$$. If $$$b$$$ is not good, we will have: $$$ acc[i][k]-acc[j-1][k] = \frac{i-j+1}{2} $$$ if $$$b_{\left\lfloor \frac{m + 1}{2} \right\rfloor} = k$$$.
Here $$$acc[i]$$$ is just the presum of the $$$cnt$$$ for subarray $$$a[0...i]$$$.
For simplicity let's denote $$$acc[i][k]$$$ as $$$p_i$$$ and $$$cnt[i][k]$$$ as $$$c_i$$$.
We will have $$$ p_i-p_{j-1} = \frac{i-j+1}{2} $$$. So $$$ 4p_i-2i+1 = 4p_{j-1}-2(j-1)+1 $$$.Notice that if $$$b_{\left\lfloor \frac{m + 1}{2} \right\rfloor} = k$$$ then $$$k$$$ must appear in subarray $$$b$$$, so we also need $$$c_i-c_{j-1}!=0$$$.
4.Maintain a hash table to count the number of bad subarray.
Solving D felt so good, finally CM-ing. Loved the contest! The question quality was really nice, although difficulty of C felt a bit off compared to normal C's.
u r sus. U have comments in your code + u have skipped code.
i tend to comment my code in harder questions. also i have never had a skipped contest wtf ? cope for your skill issue instead of being jealous
u have a GPT generated code that got skipped in round 949. lol, Cope? I feel pity not jealousy for losers who are so low IQ that they need GPT for div2 B.
my good sir, that code was copied from geeks for geeks since it was a standard function (you can verify this).. i resubmitted it after i found a better solution, not knowing that resubmitting an AC makes your previous AC submission skipped
if you have enough braincells, you should realize that a skipped submission due to copying makes your whole contest skipped, and that contest was rated for me
why would you resubmit a question that u already had AC? Dont get the point. Did you predict its gonna get skipped?
i didnt know at the time that re-submission costs you lol. i wasnt able to solve D and felt like i worked out B myself (instead of just googling bitwise or of a range: https://www.geeksforgeeks.org/bitwise-or-or-of-a-range/ the code is this exact article btw), and i wanted to resubmit my new soln.. didnt want to waste time till contest ended because i literally didnt know it would cost me ?
and fyi i am icpc regionalist in my region with like ~ 50 onsite rank, so baseless accusations like this are quite offensive
Also fyi i hate cheaters too (you can see my controversial blog replies to some posts), but sometimes you should think a bit more before making accusations ??
You being good doesnt mean you wont cheat. Masters have been caught cheating. Someone said this when psychotic_d was caught. "Anyone can cheat. An expert can cheat to become CM, An international Master can cheat to become LGM, only person who probably dont benefit from cheating is tourist himself in his prime". So thats a lame excuse. Hopefully you dont cheat but u r definitely sus.
Sure, but it does add credibility.
And it is kind of lame that instead of apologizing for making accusations without much evidence (for example, being unaware that resubmitting after getting an AC makes your submissions skipped, and that submissions skipped due to cheating skip your whole contest), you still quote "anyone can cheat".
Sure bro, with that logic, you can be a cheater too. Maybe, have some actual evidence (like a skipped contest?) before making such accusations ?
I guess the problem writer chose $$$n≤100$$$ in problem C because they also do not have a good way to calculate the value of $$$g(a)$$$.The small range of $$$n$$$ makes a brute-force search of all cases possible. I think this is probably not what they wanted.
For problem C, simple solution, we can do 1 1 2 3 ... upto (n-3) 1 2. with this method the length of longest palindrome subsequence will always be 3.
You printed $$$n+1$$$ elements for each test case instead of $$$n$$$. Therefore, the checker read
1 1 2 3 4 1for the first case, and read2 1 1 2 3 4 5 6 7for the second case. Note that it doesn't care whether the elements are on the same line or not. With2 1 1 2 3 4 5 6 7, the longest palindrome subsequence is2 1 1 2, of which the length is indeed $$$4$$$.I've just found the solutions of bieybay are obfuscated (sample: 301404672, 301404858, 301405070), which is against the contest rule. This person should be disqualified.
How did MamurjonDeveloper solve b in 2 mins .... his submissions seems sus.maomao90
impudent cheater
i guess no admin checked, sad
For me $$$A \gt B \gt C$$$
Try this problem
What's with the constraint of n in C? Why is it so small?
Also you can just put random distinct numbers at the end of the 3rd sample answer, as g(a)=190 which is >=100
because the checker took O(n^2) to check if your sequence is valid every test case
In the second matrix of the B's sample, it says that p1 < p3 and p1 < p5, but why the output is p1 = 4? Can anyone explain that to me?
It is a bit confusing for example p3 (node 1) in the permutation satisfies the condition p3<p4 so p3=1 and p4=3 there is a edge between them
B is not a graph algorithm problem actually
So is B incorrect or am I confused in somethings bro ?
It is a bit hard to understand youre wrong
Slowest first solve for A problem
Still you cooked !!
I think first solve also need to divided into div 2 and div 1+2,I don't want to lost my problem C"s first solve.
For some reason i felt B should have been C and C should have been B in this contest. :P
both of them are div2B in my opinion
but yeah C took me 21 minutes to solve B took 28
i wasted most of my time on B just to realise after contest it was simple toposort. C was ig done in 10 minutes.... should have tried C 1st
no just greedy toposort is :skull:
how can I become a tester of official div2 round
b is bit confusing
a and c are doable
Hello,
I would like to clarify that I did not copy any solution during the contest.
I solved the problems independently based on my understanding. I understand that multiple of my submissions were flagged, possibly because many participants arrived at similar approaches.
I did not share my code or use any external/public source during the contest.
If required, I can explain my approach in detail.
Thank you.