sunbrey's blog

By sunbrey, 8 days ago, In English

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:

  1. MikeMirzayanov for Polygon and Codeforces platforms.

  2. Friendiks, KotlechkovEgor, semwin2008 for helping me improve the problems.

  3. 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!

UPD: Editorial is out.

  • Vote: I like it
  • +282
  • Vote: I do not like it

»
7 days ago, hide # |
 
Vote: I like it -24 Vote: I do not like it

6 testers working overtime so I can get WA on test 2 in problem A. Respect!

»
7 days ago, hide # |
 
Vote: I like it +49 Vote: I do not like it

wow we had MikeMirzayanov as an author and now as a tester!

»
7 days ago, hide # |
 
Vote: I like it +7 Vote: I do not like it

Waiting for Mike to comment "As a tester..."

»
7 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Love when problems share a connected storyline! Looking forward to the round, thanks for preparing it :3

»
7 days ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

Sir Mike as a tester hits crazy, now Sir Mike only wasn't translator if I'm right?

how you think guys?

  • »
    »
    7 days ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    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: :)

    • »
      »
      »
      43 hours ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      ooooooooooo

      are u also a BIL student? I am, and also am a Lololowka fan!!!

      anyway, sorry for the out of topic comment, but yh i wish i could participate in this contest as i planned to, but js forgor at the end...

»
7 days ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

cute plushies

»
7 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

i hope i cross 1300 in this contest

»
7 days ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

Black testing orz

»
7 days ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

is that omori & aubrey on the picture? how cute

»
7 days ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Omori round <3

»
7 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Good luke,guys!/Удачи, друзья!

»
6 days ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Who're the two cute characters in this picture?

»
6 days ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Hello!

This is gonna be my first round actually, and I am pretty excited!

I wonder what rank would I get... :)

»
6 days ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

no game theory problem please

»
6 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hi lol

»
6 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

i came, i saw, i solved, i solved, i kept solving, i got -ve, i slept.

»
6 days ago, hide # |
 
Vote: I like it +12 Vote: I do not like it

I shed a tear...

»
6 days ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Isn't that Omori and Aubrey ? Kinda cute to see em here

»
6 days ago, hide # |
← Rev. 2  
Vote: I like it -7 Vote: I do not like it

.

»
5 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

So excited to read the story!

»
5 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Thanks for the contest!!

»
5 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

good luck everyone

»
5 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Drop a like for a cookie, please

»
5 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

omori round we sleeping good tonight

»
5 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Its my first, it starts in 10 mins. I am scared!

»
5 days ago, hide # |
← Rev. 2  
Vote: I like it +2 Vote: I do not like it

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?

  • »
    »
    5 days ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I'm in the same boat, my account Catman6094 got disabled. I really want to at least know why this happened.

    • »
      »
      »
      5 days ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      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.

»
5 days ago, hide # |
← Rev. 2  
Vote: I like it +1 Vote: I do not like it

Is this a real div3 contest?

»
5 days ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

holy difficulty

»
5 days ago, hide # |
← Rev. 8  
Vote: I like it +5 Vote: I do not like it

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

Spoiler
  • »
    »
    5 days ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Could you explain the math in $$$E$$$ in more detail? How did you derive the solution from the start?

  • »
    »
    5 days ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    bruh i was hesitant to dp for D cuz div3 D. Thank you for the sols <3

  • »
    »
    5 days ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    How do you arrive at that conclusion for problem C? How can we find that invariant?

    • »
      »
      »
      5 days ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      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 01 or 10 work

      You can keep any other string non-alternating and therefore it will eventually end up as 00 or 11

      • »
        »
        »
        »
        5 days ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        that was your thought during the contest ? you had to guess that

        • »
          »
          »
          »
          »
          5 days ago, hide # ^ |
          ← Rev. 2  
          Vote: I like it 0 Vote: I do not like it

          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.

        • »
          »
          »
          »
          »
          5 days ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          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.

        • »
          »
          »
          »
          »
          5 days ago, hide # ^ |
          ← Rev. 2  
          Vote: I like it +8 Vote: I do not like it

          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$$$).

          • If $$$l \ge 4$$$, you can simply remove one 00.
          • If $$$l=3$$$, the string should contain 1000 or 0001 (because $$$n$$$ is even). Here you can apply the operation on 000 and you'll have 11 as the result.
          • If $$$l=2$$$, there are three possible cases.
            • If the entire string is 00, just remove them, and you are done.
            • If the string contains 0010 or 0100, then apply the operation on 010 and you have 00.
            • Otherwise, the string should contain 0011, 1001 or 1100. Just remove 00 and move on.
        • »
          »
          »
          »
          »
          5 days ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          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.

  • »
    »
    4 days ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Could you explain bonus G in depth

    • »
      »
      »
      4 days ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it
      Spoiler
»
5 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
  • »
    »
    5 days ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    It isn't a greedy, it's a dp.

  • »
    »
    5 days ago, hide # ^ |
    ← Rev. 2  
    Vote: I like it +10 Vote: I do not like it

    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.

  • »
    »
    5 days ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    L: 1 100

    R: 5 5

    S will avoid but if it takes to the final result will be better than avoiding

  • »
    »
    4 days ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    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 .

»
5 days ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

Guessforces

»
5 days ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

C was a nightmare to guess

  • »
    »
    5 days ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    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.

»
5 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

OH GOD THIS ROUND TOUCHED ME INAPPROPRIATELY

»
5 days ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

What are these names man

»
5 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Great contest, unfortunately I ran out of time before I could finish implementing F. Finally Specialist :D

»
5 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I don't know how to use dp to solve D...

»
5 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Does no greedy approach work for Problem D?

»
5 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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 ❤️.

»
5 days ago, hide # |
← Rev. 2  
Vote: I like it 0 Vote: I do not like it

4k people solve d! i think my rating is going to drop a lot

»
5 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Solved E but not D ToT

  • »
    »
    5 days ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    how bro , D was easier then C and i couldn't solve E

    • »
      »
      »
      5 days ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      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

      • »
        »
        »
        »
        4 days ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        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

        • »
          »
          »
          »
          »
          4 days ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          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

          $$$ F(d)=xd-(2^d-1). $$$

          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

          $$$ \boxed{a+mx \gt H_m} $$$

          is not only necessary but also sufficient for surviving $$$m$$$ rounds. This justifies the binary search.

          • »
            »
            »
            »
            »
            »
            4 days ago, hide # ^ |
             
            Vote: I like it 0 Vote: I do not like it

            "block boundaries have non-increasing first differences" this part gave me clarity, thanks :)

»
5 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Personally, I really liked the stories involving questions that were interconnected!

»
5 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

E looks like >:D

»
5 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

E seemed to be some reverse engineered maths formula

»
5 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
5 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

peakmori round :O managed to solve A-G but not F it was lwk hard >w<

  • »
    »
    5 days ago, hide # ^ |
     
    Vote: I like it +4 Vote: I do not like it

    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)

  • »
    »
    5 days ago, hide # ^ |
     
    Vote: I like it +10 Vote: I do not like it

    Same qwq

»
5 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

such a boring two weeks with no normal contests :(

»
5 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

how to access editorial or blog regarding this contest??

»
5 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

D cooked mee

»
5 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

ughh 8 mins short for H

  • »
    »
    5 days ago, hide # ^ |
    ← Rev. 2  
    Vote: I like it +10 Vote: I do not like it

    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.

    • »
      »
      »
      5 days ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Create two copies of every vertex — one for pink (u) and one for black (u+N), where N is the number of vertices.

      Edge Construction

      For each edge:

      • Pink edge → add (u, v+N) and (v, u+N)
      • Black edge → add (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

»
5 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

way to bring back omori trauma :')

»
4 days ago, hide # |
← Rev. 2  
Vote: I like it 0 Vote: I do not like it

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?

  • »
    »
    4 days ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Because you are more clever than AI. Those who clever than AI often got this kind of terrible stuck.

  • »
    »
    4 days ago, hide # ^ |
     
    Vote: I like it +10 Vote: I do not like it

    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.

    • »
      »
      »
      3 days ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      I mean almost everyone has more than 1 account and everyone knows it. Moreover, they disabled it not because I had 2 accounts but rather because they falsely assumed it to be doing malpractise, so they should correct it

»
4 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

why are so many succesful hacks getting TLE verdict on problem D?

  • »
    »
    4 days ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    maybe some ppl may have used recursion + memo (using map ) ??

  • »
    »
    4 days ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    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.

»
4 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I have a question, how to have a CP online community where everyone discuss about CP and improve together

»
4 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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?

»
4 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I really like problem H although I can not solve it in Contest ^^, but now I can solve it. The idea burned my head ^^

»
4 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I participated in the live contest, but my profile still shows no rating change.That's why??

»
4 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

New color :yayy:

»
4 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

wow, i dont expect, what this tasks will be about Omori game :)

»
4 days ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

can someone explain H?

  • »
    »
    4 days ago, hide # ^ |
    ← Rev. 3  
    Vote: I like it +4 Vote: I do not like it

    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 :

    U
    |
    V
    

    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.

»
4 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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.

»
4 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can anyone pleasee explain how to solve problem H

»
4 days ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

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:

  • Problem A: 5 minutes after the beginning of the contest
  • Problem B: 11 minutes after problem A (after a wrong answer because I forgot to use 64-bit integers lol)
  • Problem C: 8 minutes after problem B
  • Problem D 12 minutes after problem C

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!

»
4 days ago, hide # |
← Rev. 2  
Vote: I like it 0 Vote: I do not like it

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.

»
4 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like 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.

  • »
    »
    3 days ago, hide # ^ |
     
    Vote: I like it +11 Vote: I do not like it

    Here was my intuition

    Each compliment resets Aubrey's speed to 1, splitting the game into k+1 blocks where she moves 2^L — 1. Since 2^L — 1 is convex, the block lengths differ by at most 1. By putting shorter blocks first, the minimum is at the end. Sunny only loses the lead once it's length passes floor[log_2 x]+1, so start there and grow blocks layer by layer.

  • »
    »
    3 days ago, hide # ^ |
    ← Rev. 2  
    Vote: I like it +1 Vote: I do not like it

    Here is how you can solve E problem.

    First observation: Distance travelled by Aubrey is of the form $$$2^0 + 2^1 + 2^2 + ...$$$ until she gets flustered (distracted) by Sunny's compliment and starts again like $$$2^0 + 2^1 + 2^2 + ...$$$ adding up to the previous distances traversed by her. Hence we can say that Aubrey's total distance is of the form $$$\left(\underbrace{11111\ldots}_{\text{few times}}\right)_2+\left(\underbrace{11111\ldots}_{\text{few more times}}\right)_2+\left(\underbrace{11111\ldots}_{\text{few more times}}\right)_2+...$$$ and so on. Also the total number of $$$1$$$'s in this expression is the number of rounds for which they have played. Also the number of terms of the form $$$\left(\underbrace{11111\ldots}_{\text{few times}}\right)_2$$$ is equal to $$$k$$$ because $$$k$$$ is the number of times Sunny can compliment Aubrey to distract her.

    Second Observation: Now let's fix the number of rounds we are going to have. Let's have $$$mid$$$ number of rounds (Binary search is coming). This simply means that we have $$$mid$$$ number of $$$1$$$'s to use in the expression for Aubrey's distance. And talking about Sunny, he would have travelled a distance equal to $$$mid \times x$$$. Our goal is to minimize the distance distance covered by Aubrey after $$$mid$$$ rounds (because we don't want her to takeover Sunny). It turns out that if we divide the $$$mid$$$ number of $$$1$$$'s we had into $$$k$$$ groups such that each group has almost equal number of $$$1$$$'s, minimum value of Aubrey's distance is achieved in the expression of the first observation. All we need to do is to make sure that this minimum value is less than Sunny's final position, i.e., $$$a+mid \times x$$$.

    (I have not discussed how to divide evenly the $$$mid$$$ number of $$$1$$$'s into $$$k$$$ groups to achieve minimum distance because I want you to think and spend time on this).

    Third Observation: This is a simple one. If Aubrey can takeover Sunny after $$$mid$$$ rounds, she can do that after $$$mid+1$$$ rounds also. This means that we can binary search on the number $$$mid$$$.

    This is my code for your reference:

    #include<bits/stdc++.h>
    using namespace std; 
    #define int long long 
    #define endl '\n'
    void solve(int test) {
        int A, X, K; cin >> A >> X >> K; 
        K++;
        int ans = 0; 
        int l = 0, r = 30*(K); 
        while (l <= r) {
            int m = (l + r) >> 1; 
            int q = m/K; 
            int rem = m%K; 
            if (q >= 63) {r =m-1; continue;} 
            int val1 = rem * ((1LL << (q+1))-1) + (K-rem)*((1LL << q)-1); 
            int val2 = A + m*X; 
            if (val2 > val1) {ans = m; l = m + 1;}
            else {r = m-1;}
        }
        cout << A + ans*X << endl;
    }
    int32_t main () {
    ios::sync_with_stdio(false); 
        cin.tie(nullptr);
        auto start = chrono::high_resolution_clock::now(); 
        int T = 1; 
        cin >> T; 
        for (int i=1; i<=T; ++i) {
            solve (i); 
        }
        auto end = chrono::high_resolution_clock::now();
        auto duration = chrono::duration_cast<chrono::microseconds>(end-start);
    
        cerr << "Execution time: " << duration.count()/1000.0 << " ms\n";
        return 0; 
    }
    
»
4 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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 ... ...

»
3 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I've been stuck at C for a long time(about an hour). Finally i found it that it is easy. A good thinking problem though. But beyond my expectation is that D is a dp! i'v been thinking how solve it with greedy :(

»
3 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

When is the editorial arriving?

»
3 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Where is the editorial

»
3 days ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

it should have been me! not sunny

»
3 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Dear Codeforces Support Team,

I am writing to sincerely appeal for the unblocking of my account, GoldenFishKnight. I was deeply saddened to find that my account has been disabled. I firmly believe this is a false positive, and I would like to explain the circumstances that might have triggered your security system.

After browsing similar cases in the community, I suspect my account was flagged due to the following reasons:

  1. Unintentional VPN Usage (IP Change): I am currently located in Mainland China. During my participation in the recent contest, I forgot to turn off my VPN (proxy). As a result, my login IP appeared to be from Hong Kong. I completely understand that Codeforces has strict rules against IP fluctuations to prevent cheating, but this was purely an unintentional mistake on my part.

  2. Sudden High Performance and Account History: I understand that my sudden high rank in this contest might look suspicious. To be completely transparent: I actually had an old Codeforces account a couple of years ago, but because I stopped participating for the last two years, I completely forgot its password and cannot recover it. Therefore, I created this new account.

However, I am NOT engaging in multi-accounting or cheating. This is the only account I am currently using. The reason I achieved a high score is that although I stopped playing on Codeforces, I have been training rigorously on other platforms over the past two years. I have attached screenshots of my LeetCode (China site) weekly contest stats as proof.    As you can see, I ranked 56th in Contest 421 and 84th in a recent contest. This proves that my recent high performance on Codeforces is the result of my genuine, long-term hard work and consistent practice, not any form of cheating or unauthorized assistance.

I deeply respect the Codeforces community and the rules of fair competition. I apologize if my negligence regarding the VPN caused any trouble for the administration, and I promise to be extremely careful and ensure my network is clean for all future contests.

I kindly request a manual review of my account and my submission history.

Thank you for your time and understanding. I look forward to your reply.

Best regards, GoldenFishKnight

MikeMirzayanov