Hello, Codeforces :3
I am thrilled to invite you to Codeforces Round 1138 (Div. 3), which will start at Nov/27/2026 17:35 (Moscow time).
Then round will last 2 hours and 15 minutes and you will be given 7-8 problems to solve. The round will be rated for participants with a rating lower than 1600.
Remember that only the trusted participants of the third division will be included in the official standings table. As it is written by link, this is a compulsory measure for combating unsporting behavior. To qualify as a trusted participant of the third division, you must:
- take part in at least five rated rounds (and solve at least one problem in each of them)
- do not have a point of 1900 or higher in the rating.
Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you.
I put a lot of effort into preparing this round, and I hope you’ll enjoy reading the problem statements as much as I enjoyed writing them. Each problem picks up where the previous one left off. I hope you’ll make it to the last problem and read the story all the way to the end.
I would like to thank Vladosiya for the helpful feedback and assistance with preparing the problems. Special thanks to:
MikeMirzayanov for Polygon and Codeforces platforms.
Friendiks, KotlechkovEgor, semwin2008 for helping me improve the problems.
MikeMirzayanov, zhichenlin, Timosh, wery0, JedbyKey999, itz_pabloo, vanta5n, grigalex40, xinerx for colorful and wonderful testing.
The round will be hosted by rules of educational rounds (extended ICPC). Thus, solutions will be judged on preliminary tests during the round, and after the round, it will be a 12-hour phase of open hacks. After open hacks all accepted solutions will be rejudged on successful hacks.
Good luck and have fun!









6 testers working overtime so I can get WA on test 2 in problem A. Respect!
wow we had MikeMirzayanov as an author and now as a tester!
Waiting for Mike to comment "As a tester..."
Love when problems share a connected storyline! Looking forward to the round, thanks for preparing it :3
Sir Mike as a tester hits crazy, now Sir Mike only wasn't translator if I'm right?
how you think guys?
P.s mister sunbrey i show my greatest respect that you have payed so much time for us, Div. 3 and I'm glad that I can take part in this contest and read storyline that you've worked out. Thank you!:heart: :)
cute plushies
i hope i cross 1300 in this contest
Black testing orz
you like it black?
is that omori & aubrey on the picture? how cute
Omori round <3
(Waiting for this round to happen?)
(You have been waiting here for as long as you can remember.)
elite ball knowledge
Good luke,guys!/Удачи, друзья!
Who're the two cute characters in this picture?
congrats on gm!
Yo congrats on GM
Also I didn't realize it's you because your color changed and your pfp changed too...
They're Aubrey and Sunny from the game OMORI
Thank you all (From a TA busy authoring problems for DSA class's final exam and busy preparing for her own another one, :sob)
Hello!
This is gonna be my first round actually, and I am pretty excited!
I wonder what rank would I get... :)
no game theory problem please
haha, You guessed it
Hi lol
i came, i saw, i solved, i solved, i kept solving, i got -ve, i slept.
I shed a tear...
Isn't that Omori and Aubrey ? Kinda cute to see em here
.
So excited to read the story!
Thanks for the contest!!
good luck everyone
Drop a like for a cookie, please
omori round we sleeping good tonight
Its my first, it starts in 10 mins. I am scared!
My account ilia_rr just got disabled mid contest. Is there an official procedure for appealing the suspension or contacting the administration to have my account reviewed?
I'm in the same boat, my account Catman6094 got disabled. I really want to at least know why this happened.
It says "Unexpected Precipitation, Skipped" as verdict. It probably is the automatic cheat detection system, so there should be a way to request a review.
Is this a real div3 contest?
holy difficulty
Nice contest, here are solution sketches for A-G:
A. Simulation, $$$O(l+a+b)$$$
B. Sort the array, and for every block of $$$k$$$ consecutive elements either eat them individually or make juice, whichever is optimal, $$$O(n \log n)$$$ due to sorting
C. The answer is YES if and only if $$$n$$$ is even and the string is not alternating, $$$O(n)$$$
D. Right to left DP, store the best possible score for each player (max for Sunny, min for Aubrey) if they are currently on the left, transitions are $$$dps_n = \max(x_n-y_n, 0)$$$, $$$dpa_n = \max(y_n - x_n, 0)$$$, $$$dps_i = \max(x_i - y_i + dps_{i+1}, dpa_{i+1})$$$, $$$dpa_i = \max(y_i - x_i + dpa_{i+1}, dps_{i+1})$$$, answer is based on $$$dps_1$$$, $$$O(n)$$$
E. Binary search on the answer, for $$$m$$$ steps the smallest possible position of Aubrey where $$$y = \lfloor m/(k+1) \rfloor$$$ and $$$z = m - y(k+1)$$$ is $$$(2^y-1)(k+1-z) + (2^{y+1}-1)(z)$$$, $$$O(\log^2 k)$$$
F. Create an auxilliary directed graph of $$$2n$$$ nodes where $$$n$$$ are a "black mode" and $$$n$$$ are a "pink mode" which represent the next edge color you must traverse to keep the path alternating, and check if there is a cycle in it, $$$O(n+m)$$$
G. Sort the array, the optimal set of pictures to choose for a tournament is the first $$$n/2$$$ and last $$$n/2$$$, the optimal order eliminates the largest elements last, brute force on every tournament size, $$$O(m \log m)$$$
Trivial bonus for G: Solve it with update queries
All possibilities can be checked in $$$O(\log m)$$$ total time with prefix sums so just walk on a sparse segment tree
Could you explain the math in $$$E$$$ in more detail? How did you derive the solution from the start?
We want to minimize the powers of 2 used, so we do our best to evenly distribute the compliment points, 2149F - Nezuko in the Clearing uses the same construction but with triangular numbers
bruh i was hesitant to dp for D cuz div3 D. Thank you for the sols <3
How do you arrive at that conclusion for problem C? How can we find that invariant?
The even length is pretty simple as you delete 2 bits every time
For the alternating string condition we can see that the operation keeps the string alternating and neither
01or10workYou can keep any other string non-alternating and therefore it will eventually end up as
00or11that was your thought during the contest ? you had to guess that
I noticed that alternating strings didn't seem to work and I tried them and saw that it was because they stayed alternating, then tried a few other cases knowing this condition to see if everything else worked. And the even one isn't very hard. It was definetly quite guessy though.
Try to perform it on an alternating string, the operation does not change it, rest all strings can be emptied. Try it on a no. of different string combinations, you'll see that. So, I don't think it was guessing, just observation.
If the initial string isn't alternating, then it's always possible to keep the string non-alternating after an operation, provided that $$$n$$$ is even.
For simplicity, let's say the string has the longest contiguous span of
0s. Let $$$l$$$ be the length of the span ($$$l \ge 2$$$).00.1000or0001(because $$$n$$$ is even). Here you can apply the operation on000and you'll have11as the result.00, just remove them, and you are done.0010or0100, then apply the operation on010and you have00.0011,1001or1100. Just remove00and move on.I did write all 16 strings with lenght equal to 4 and then guessed it. Then I just needed a prove (or just some half prove) which wasn't that hard to find.
Could you explain bonus G in depth
Know the solution for the original G. For a tournament of size $$$n$$$ the sum can be decomposed into the following ranges:
Increasing the tournament size only changes the amount of selected ranges by 2. Therefore we need to sum $$$O(\log m)$$$ ranges for each query. We have reduced it to the following problem:
This can be solved online with a sparse segment tree. Store for a value how many elements are currently equal to that value. Then for each query we can binary search for the first node such that the sum of the amount of values is the necessary amount for the query. This is $$$O(q \log m \log^2 (m+q))$$$, but we can cut a log factor by walking on a segment tree, making the final complexity $$$O(m \log m + q \log m \log (m+q))$$$.
What is wrong with D?
https://codeforces.me/contest/2292/submission/400061674
It isn't a greedy, it's a dp.
I think my solutions is already using dp (state transition) without naming the variables dp ^^
Anyway, do you have a counter example?
Greedy Approach will not work in this case. Try to map the problem to the House Robber problem.
And the reason why Greedy algorithm fails here is because skip doesn't mean a +0 but toggling the authority to someone else for later spendings.
Can you please give a counter example that beats my solution?
N = 4, X = {1, 1, 1, 3}, Y = {2, 1, 4, 1}. Answer should be Draw.
L: 1 100
R: 5 5
S will avoid but if it takes to the final result will be better than avoiding
My code outputs Sunny for your example
Choosing a bigger number at an instant seems correct but think in terms of future , there maybe some choice that may not yield good at current moment but can be fruitful later , so greedy fails here we'll apply DP its because we have only two choices either skip or buy , and if we know the result for upcoming suffix( the subproblem we want to know answer of) then player can easily make a choice at index i to be at the left or swap positions , Consider reading minimax DP for more info .
Guessforces
C was a nightmare to guess
I think I arrived at a complete proof.
Odd lengthed or alternating strings are bad, so we talk about even lengthed and non alternating ones.
Suppose we pick the pair (i, j) and call P = s[0 ... i — 1], X = s[i + 1 ... j — 1] and S = s[j + 1 ... n — 1]
Claim: We can force PXS to be non alternating (empty strings are assumed to be alternating)
Assume, that s[i] = s[j] = '0'
The only way PXS can be alternating iff P, X and S are alternating and X connects to P and S with the same bit before flipping.
First, assume that at least one of P and S is non empty. Assume that it is P and S is empty for convenience.
The only problematic triplets are 101 and 000. However, 101 is not possible under our assumption because s itself would be alternating in this case.
In 000, simply pick any but the middle 0 and the resulting string contains at least one equal and adjacent pair.
If both P and S are empty and n >= 4, we can select a suitable same bit from X to reduce it to the previous cases.
If X is empty, then there must exist only one pair of 0s and that too adjacent ie only one occurrence of "00". Even in this case, we can reduce the string to an empty one.
So, I think the conditions are sufficient. I would be happy to have someone hack this.
Actually, C can be solved by induction on size of string and claiming that 010101... reduces to 01 and 10101010... to 10. If there are 2 consecutive equal, we can now make cases to reduce either side of it and since size decreases, we use induction. Was stumped by it for long :)
I am also talking about induction. I just wanted to prove the sufficiency of the two conditions. Necessity is trivial.
Yes
OH GOD THIS ROUND TOUCHED ME INAPPROPRIATELY
What are these names man
Great contest, unfortunately I ran out of time before I could finish implementing F. Finally Specialist :D
I don't know how to use dp to solve D...
Does no greedy approach work for Problem D?
No, since choosing a smaller number might let you get a better result later on. You need DP.
Really enjoyed the questions in this round, sadly didn't do as well as I was hoping to but really liked the story part of these questions ❤️.
4k people solve d! i think my rating is going to drop a lot
Yeah, same here.
Solved E but not D ToT
how bro , D was easier then C and i couldn't solve E
Not good at DP :( For E, the answer is monotonous and an upper limit is given, so use binary search. For each round you're checking, apply the compliments evenly so that Aubrey climbs the slowliest because she climbs faster and faster without the compliments. https://codeforces.me/contest/2292/submission/400052197
1) I got the point the runs of Aubrey should be almost equal length
2) Let's say we fix the no.of rounds R, then q = R/k+1 and rem = R%(k+1), then (k+1-rem) runs are of length q and rem rounds are of size q+1
3) In this approach we can only check whether Aubrey crosses sunny after the last run, how to prove that it does not cross at any run in the middle
These contents are translated by GPT.
We need to prove that checking only the final positions is sufficient, even though Sunny must stay strictly ahead after every round.
Let $$$q=\lfloor m/(k+1)\rfloor$$$ and $$$r=m\bmod(k+1)$$$. The optimal strategy divides the $$$m$$$ rounds into $$$k+1$$$ blocks: $$$r$$$ blocks of length $$$q+1$$$, and the remaining blocks of length $$$q$$$. A block of length $$$d$$$ makes Aubrey climb $$$2^d-1$$$ steps.
Define the net contribution of a block as
We can arrange the blocks in non-increasing order of $$$F(d)$$$. Then, the differences between Sunny's and Aubrey's positions at consecutive block boundaries have non-increasing first differences. Thus, these differences form a discrete concave sequence.
The same argument applies inside each block: after $$$s$$$ rounds, the position difference changes by $$$x-2^{s-1}$$$, which is also non-increasing. Hence, the position difference is discretely concave within every block as well.
A discrete concave sequence attains its minimum at one of its endpoints. Therefore, if the initial and final position differences are both positive, the difference must remain positive at every intermediate round.
Consequently, the condition
is not only necessary but also sufficient for surviving $$$m$$$ rounds. This justifies the binary search.
"block boundaries have non-increasing first differences" this part gave me clarity, thanks :)
Personally, I really liked the stories involving questions that were interconnected!
E looks like >:D
E seemed to be some reverse engineered maths formula
Hello sunbrey Vladosiya MikeMirzayanov
My account lydxn got disabled during the contest. I'd be grateful if an admin could check my account and a reason for the ban. As far as I'm aware I haven't broken any rules with regards to cheating or AI.
Thanks
peakmori round :O managed to solve A-G but not F it was lwk hard >w<
Actually there is a simple solve for F: We can decompose the given graph as follows: a vertex $$$2u$$$ in the new graph will represent vertex $$$u$$$ from the original graph if we reached it via a black edge, while a vertex $$$2u + 1$$$ will represent vertex $$$u$$$ if we reached it via a pink edge. Once the edges in new graph are added correctly, we simply need to check for the presence of a cycle within each component of the decomposed graph (i used translator so sorry if smth is not understandable)
holy hell thats a nice solution brilliant of you to have seen that thank you
Same qwq
such a boring two weeks with no normal contests :(
how to access editorial or blog regarding this contest??
D cooked mee
ughh 8 mins short for H
Congrats on 97th* (standings were weird, mb) as a newbie, curious how you did F? I had an idea, but I feel I overcomplicated it too much and was wondering if someone so strong as yourself could explain.
Create two copies of every vertex — one for pink (
u) and one for black (u+N), whereNis the number of vertices.Edge Construction
For each edge:
(u, v+N)and(v, u+N)(u+N, v)and(v+N, u)Each edge forces the "opposite side" vertex onto the other copy, which keeps the two colors consistent.
Cycle Check
Build the graph, then run topological sort. If the sort fails → there's a cycle → invalid.
Component Count
Count the number of distinct roots in the DSU. Each different root = one separate component.
400045603
LOL you made it worse bro
BTW I asked how YOU did F. Not how AI did it for you :)
nope, that's my own code — didn't come from AI
only comments. :(
Imagine cheating and still losing to hit fraud sc3developer
My idea for F was mostly the same as the slop above except you don't need toposort to detect cycles I just copied from geeks for geeks
i hate dfs
You mean your AI model hates DFS?
omg
Explain more concretely, step by step, plz. I can not understand at all.
I got it solved (shoutout to qqrnt for helping me!) with similar DSU idea but I used SCC instead of topological sort
Only finding a cycle, you used SCC? Isn't it too expensive?
No? Both are $$$O(V + E)$$$. (Unless you were talking about expensive not in terms of runtime?)
SCC is only a bit heavier and gives a bit extra constant factor. though they're the same asymptotic complexity of $$$O(V+E)$$$. i think using SCC is still an overkill though since topo sort is simple. (。・ω・。)
way to bring back omori trauma :')
Hey Guys, sunbrey, MikeMirzayanov
thehvd3.redemption(click here) this is my account, while I was giving contest today, it was suddenly disabled. I request the moderators to please enable my account, as I was not doing any kind of cheating nor was I using AI. Also, what was the reasoning for disabling my account? Was it just the fact that a newbie account solved 4 que in 30 min?
Because you are more clever than AI. Those who clever than AI often got this kind of terrible stuck.
I can't see your submissions for some reason, but I could imagine having 2 accounts doesn't exactly increase your chances of an appeal.
why are so many succesful hacks getting TLE verdict on problem D?
maybe some ppl may have used recursion + memo (using map ) ??
I saw many people had the same solution with different variable names, stuff moved around and different templates: bottom-up 2D DP that checks if a state has been computed by asking if dp[x][y] != -1. Then a hack forces as many as possible valid states to be -1 so that at every step of recursion it has to reconstruct the whole memo table, thus O(n²) time.
I have a question, how to have a CP online community where everyone discuss about CP and improve together
Hello, I submitted a solution for problem D during Codeforces Round 1138, but it does not appear in my submissions or the standings. My handle is bhaumik2427, and I submitted at approximately 10:20 pm in India using C++. Could you please check whether the submission was received?
I really like problem H although I can not solve it in Contest ^^, but now I can solve it. The idea burned my head ^^
Thanks. My problem.
Thank you for creating a great problem and for everything you do on Codeforces Community ^^
Big Fan from VietNam
Another big fan from Vietnam :D
I participated in the live contest, but my profile still shows no rating change.That's why??
New color :yayy:
wow, i dont expect, what this tasks will be about Omori game :)
can someone explain H?
Consider the information of each node independently, let it be $$$u$$$ and suppose it is the root. Call an $$$i$$$ good if it's the first time $$$e_i$$$ transfers information from the parent to the child, the amount of people knowing the info of "$$$u$$$" is the amount of good $$$i$$$.
Note that this sum only changes if we remove one of the good $$$i$$$, and the next time the same edge $$$e_i$$$ appears again let it be $$$j$$$.
So the difference after removing $$$i$$$ is just the amount of good $$$k$$$ in the subtree of $$$e_i$$$ originally minus those $$$k$$$ coming from the new $$$j$$$.this gives the idea of dp, let $$$dp_i =$$$ the amount of good $$$k$$$ in the subtree of the edge of $$$i$$$ if $$$i$$$ were to be a good index.
we can compute it from right to left and $$$dp_i =$$$ sum of the dp for each node that is direct child of the "child" of $$$e_i$$$.the the answer is $$$dp_i - dp_{i'}$$$ for each good $$$i$$$. Where $$$i'$$$ is the next appearence of $$$e_i$$$this runs in $$$O(NM)$$$
the idea to optimize is noting that each edge has two different orientations. for example imagine an edge like this :
when we take anyone above $$$u$$$ or $$$u$$$ as root the subtree of $$$v$$$ is always the same so we can build another dp considering these orientation where $$$dp_{i, \text{flag}} =$$$ is basically the same thing of the aforementioned dp but $$$\text{flag}$$$ is $$$0$$$ or $$$1$$$ defining whose from $$$u$$$ and $$$v$$$ is the "parent"
so now we could theoretically go for each $$$i$$$ and calculating how many nodes $$$x$$$ above $$$u$$$ have $$$i$$$ as a good edge.
to discover this we can just consider the same dp but in reverse since note that a information going from $$$u$$$ to some $$$z$$$ is the same as rooting in $$$z$$$ and it goind to $$$u$$$ in reverse.
So it is just how many nodes $$$z$$$ before $$$i$$$ have edge $$$i$$$ as good minus how many $$$z$$$ before $$$i"$$$ have edge $$$i$$$ as being good (where $$$i"$$$ is the previous appearence of $$$e_i$$$).
using some precalculations for nodes we can bring the complexity to $$$O(M + N)$$$
Code
I hope it is clear, feel free to ask questions.
Hello, sunbrey and MikeMirzayanov.
I created this account solely to post an appeal on behalf of my original account, maltta900, which was disabled during this round. After reading the comments, I noticed that several other participants experienced the same issue. I would greatly appreciate it if you could manually review my case and clarify the reason why my account was disabled. And I emphasize that I've strictly followed the rules for the contest. I am willing to cooperate with the review process, provide any relevant information, and explain my submissions. I respect the Codeforces community and its rules, and I sincerely hope my case can be reconsidered. Thank you for your time and consideration.
Can anyone pleasee explain how to solve problem H
Here
I made a short comment on this yesterday, but I decided to ramble a bit more here. I'm assuming from previous comments that I should ping these people to get their attention. Feel free to let me know if I'm wrong: MikeMirzayanov sunbrey Vladosiya
I decided to join these contests a couple weeks ago, and this is my second one. I really enjoyed trying to do these problems quickly, but my account Catman6094 was "disabled by administrators" mid-contest. I got no message of any kind explaining what triggered this, and I did not cheat in any way that I know of (I didn't collaborate, plagiarize, or use AI tools in any way). Cheating is completely pointless and takes away from the joy of actually solving a problem for yourself. Cheaters clearly don't understand this joy of problem solving. Anyways I've created this new account to try and get the disabled one reenabled.
For reference, here are my solve times, which you can check on my disabled profile:
I was solving E when the account was disabled.
Do these solve times seem fast for a new user? I don't know for sure because I'm new to the community, but if so, it should be noted that I have prior experience from the Project Euler community. I got hooked on Project Euler a few years ago, and I've solved 360 problems there over the course of a few years. This experience is how I've been improving my coding skills, and it carried over to Codeforces. I don't like defending myself like this because it feels too much like bragging, but I don't know what else to say.
So I am requesting that either my account Catman6094 is reenabled or at least please give me a legit reason for the ban. It is very frustrating to be banned without being given any explanation, because I don't know how I'm supposed to defend myself. I understand the paranoia around cheaters these days, what with AI growing in power, but I hope somebody considers looking into this.
Regardless, I have really enjoyed solving problems here for the past few weeks! In this contest, I found the pattern in problem C very satisfying to spot. I love inductive patterns like this one :) I also really enjoyed problem E, but sadly didn't get to submit it during the contest. I will keep solving problems here, but I guess I'll just avoid the contests if this isn't resolved.
Thank you and have a good day!
MikeMirzayanov sunbrey
Hello Mike, sorry to bother you here. My old Codeforces account kishan108 was suddenly disabled without any warning or explanation. I cannot log in, and my profile shows "The user is disabled."
I have already contacted the administration and sent you messages, but it has been over 7 weeks without a response.
Could you please review my account and explain the reason for the restriction? If it was a mistake, I kindly request your help in restoring it.
The Editorial is taking FOREVER to come out. Can someone PLEASE explain how to solve E? I have some intuition from reading other's submissions but I am not able to prove it.
Suspected cheating in Contest 2292 by SarS0ura_404: - https://codeforces.me/contest/2292/submission/400065230 - https://codeforces.me/contest/2292/submission/400043263 - https://codeforces.me/contest/2292/submission/400028815
Please check these submissions.
It was like i didnt even solved a single problem then after the contest i thought the first question is maybe gcd and its was actually gcd ... ...