sunkuangzheng's blog

By sunkuangzheng, 16 months ago, In English

Hello, Codeforces!

auiunu, NahC0el and me are glad to invite you to the last round with 10 binary bits — Codeforces Round 1023 (Div. 2), which will start on May/05/2025 17:35 (Moscow time). You will be given 6 problems and 1 subtask with 2 hours 15 minutes to solve them.

The round will be rated for participants of Division 2 with a rating lower than 2100. Division 1 participants can participate unofficially.

All problems are authored by auiunu, NahC0el and me.

We would like to thank:

The score distribution is $$$250-750-1500-2000-2750-(2250-2500)$$$.

We hope you will enjoy and have fun in the contest. Good luck!

UPD: Congratulations to the winners and first solves!

Div. 1+2:

  1. peti1234
  2. maspy
  3. Mangooste
  4. Sugar_fan
  5. risujiroh

Div. 2:

  1. _VanGogh_
  2. rainboy
  3. If_I_lose_it_all
  4. typeshit
  5. IHaveNoMouth_IMustScream

First solves:

UPD2: Editorial is out!

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

| Write comment?
»
16 months ago, hide # |
 
Vote: I like it +33 Vote: I do not like it

As a tester, Dominater069 orz.

»
16 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

As A participant I hope Enjoy.

»
16 months ago, hide # |
 
Vote: I like it +10 Vote: I do not like it

hope to solve ABCD in 90 mins :)

»
16 months ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

What happened to the contest which was gonna take place tomorrow?

»
16 months ago, hide # |
 
Vote: I like it +125 Vote: I do not like it

OMG round $$$(1111111111)_2$$$ as a tester!

»
16 months ago, hide # |
Rev. 2  
Vote: I like it +32 Vote: I do not like it

Fun fact: The previous contest that had 250 points on A was Global Round 28, which was on December 2024

»
16 months ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

As a tester, I tested

»
16 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

As a tester, I loved the problems

»
16 months ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

250 for A and 1500 for C.

Spoiler
»
16 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

ok.. surprising that the first problem has a score of 250 .... what does this mean?

»
16 months ago, hide # |
 
Vote: I like it +27 Vote: I do not like it

People should consider solving C earlier in this round.

Explanation: If somebody can solve A in 10 min, B in 20min, and C in 40 min; The solving order A,B,C gives (250-10)+(500-60)+(1500-420)=1760 round score. On the other hand, C,B,A gives (1500-160)+(500-120)+(250-70)=2000 round score. But, if you aren't able to solve C, this would work negatively.

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

    Don’t give them ideas bro I don’t wanna start solving from C…

  • »
    »
    16 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it +10 Vote: I do not like it
    • bruh the solving order A, B, C gives (250-10)+(500-60)+(1500-280) = 1900 and not 1760
    • and the order C, B, A gives (1500-160)+(500-120)+(250-70) = 1900 and not 2000
    • so for A — 10 minutes, B = 20 minutes, and C 40 minutes the ordering does not matter

    • but assuming A is super easy and you can solve A in 5 minutes, B in 20 minutes and C in 40
    • then order A, B, and C give (250-5)+(500-50)+(1500-260) = 1935
    • and order C, B, and A give (1500-160)+(500-120)+(250-7) = 1905

    in this case A, B, C ordering will be better

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

    Seems the problem of solve which first can be solved by greedy.I should first the problem with high division of score and time. (score/time)

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

    Oh your calculation seems wrong.The grades are both 1900

»
16 months ago, hide # |
 
Vote: I like it +23 Vote: I do not like it

One of the tester is banned now lol

»
16 months ago, hide # |
Rev. 2  
Vote: I like it -11 Vote: I do not like it

finally , i'll become newbie

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

    The only benefit of starting from div3/div4 is your ratings grow faster, but not higher. I think experience one more round is better.

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

With this score distribution problem A is going to be cout << a+b << endl;

»
16 months ago, hide # |
 
Vote: I like it +51 Vote: I do not like it

luuia's testing hopefully means the round is GPT proof

»
16 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Yeah I'm out of competition now

»
16 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

So Imma prepare a template for odd-even and sum of two no.s for A.:)

»
16 months ago, hide # |
 
Vote: I like it +61 Vote: I do not like it

RGB contest

Explaination
»
16 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I hope the first problem is not just "print 2^10-1"

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

I hope to not get minus on A

»
16 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I Wish to solve D; else will get cooked..

»
16 months ago, hide # |
 
Vote: I like it +93 Vote: I do not like it

»
16 months ago, hide # |
 
Vote: I like it -23 Vote: I do not like it

I know there will be an unordered_map solution which will get hacked, which makes rewhile happy.

I know it from past experience 287756206

»
16 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

As a tester, have fun and good luck!

»
16 months ago, hide # |
 
Vote: I like it +21 Vote: I do not like it

why is hyman00 so strong?

»
16 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

As a participant, I hope a non-negative delta.

»
16 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

how many problems do i need to solve to reach pupil in this round.Also how much time should i invest

»
16 months ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

What a hard contest!

»
16 months ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

CASE_WORK_forces and WRONG_ANSWER_forces on C for me... One day I will properly test my code before submission.

I have some comments in my code but it is not AI generate I promise.

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

    Me with 5 WAs on B, such a good day...

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

      salute sir !!! LOL

      I also made one wrong in B .. I didn't check if there can be more than one occurrence of maximum value .. yikes :(

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

      I bricked on B too. I really dislike this problem... It doesn't even fit as a div2B imo, its difficulty is below A and only had a lower solve count because many people didn't see the "edge case" of multiple maximums (just my guess though). Left me so tilted I ended up bricking C too

»
16 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Is there any solution for D that don't require centroid, I don't want to implement centroid so I am very curious.

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

    There is, I chose to find a diameter path and from there, remove all nodes in the path, which isn't explicityly centroid, but it is similar.

»
16 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Does D solution use a tree structure with heap? What an interesting problem!

  • »
    »
    16 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    I solved D just by iterating to find the tree diameter :D

    Can someone prove that this algorithm doesn't TLE? It runs in about 1.5 seconds.

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

      I was thinking same. but, what to do after first diameter? no, clues!

    • »
      »
      »
      16 months ago, hide # ^ |
      Rev. 2  
      Vote: I like it +7 Vote: I do not like it

      If you cut diameter D at some iteration, next iteration your diameter will be at most D-1.

      Proof by contradiction — if in two iterations you cut two diameters of the same length D in a tree, then there must be an edge between them (since graph is connected), and then your first diameter is larger than D.

      If you remove D nodes at one iteration, then D-1, then D-2, ..., then the total number of nodes you remove O(D^2), and you do it in O(D) iterations. So at most you will have O(sqrt(n)) iterations, and total complexity is O(n*sqrt(n)).

      Maybe there is even better bound, let's see in editorial

»
16 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I made an assumption that breaking the diameter away will always make tree less than half in size .. so that my solution will not become O(n^2) .. but I don't know the proof for this.

if this is wrong I guess I might get TLE in system tests.

»
16 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I wish next time I could know more than I am cooked when I see the Time constraint is 5s for Problem D.

»
16 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

please tell me there is a simple trick to solve C .. I spent so much time ...

I was able to solve D faster ( although my D can fail system tests )

  • »
    »
    16 months ago, hide # ^ |
     
    Vote: I like it +2 Vote: I do not like it

    Mark all 0s as -inf. Then pick one of them. Let m1 be largest sum [i....j — 1] such that j = k (where k is the index of 0 we are working on) and m2 be largest sum [j + 1 ..... i]. Let m1 and m2 >= 0, then a[j] = k — m1 — m2. Just do a quick check with subarray sums at the end.

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

      ok I understand. I think this makes sense and I can see how this can avoid some of my case work. I did something similar but with a lot of case work before this.

      thanks

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

      I did same can you tell me where i went wrong mySubmission

      • »
        »
        »
        »
        16 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it
                if (mx > k)
                {
                    cout << "No\n";
                }
        

        this is wrong. in the sample

        5 10
        10101
        10 0 10 0 10
        

        an answer is possible by doing

        10 -10 10 -inf 10
        
  • »
    »
    16 months ago, hide # ^ |
     
    Vote: I like it +2 Vote: I do not like it

    Use prefix_max and suffix_max by centering any of '0'.

»
16 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

nice d2. solved A and C with tons of penalties :(

How to solve B?

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

    so if condition 3 was not there .. then it is easy ... sum all numbers and number of moves = sum so we can just check if it is even or oddd

    but condition 3 can only work in First move.. if it doesn't apply in first move .. then observe that you can never increase the value of max-min

    so we just need to check if in first move it is possible to reach a state where max-min <= k then game continues and we can have that odd-even check

»
16 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

In "C," there is no mention that the sum must be greater than -1e18.[updated]

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

    The sum must be $$$k$$$, which is $$$\leq 10^{12}$$$

  • »
    »
    16 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    If you have any segment with a sum of more than $$$k$$$ (which is at most $$$10^{12}$$$) that is wrong answer for sure.

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

      Actually, i was replace all unfixed '0' to 1e18, except one '0'. that's give wa on 4.After replace 1e18 with 1e13 got "AC".

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

        I guess you mean $$$-10^{13}$$$, right? Because using any value larger than $$$k$$$ is 100% wrong answer. I used $$$-10^{18}$$$ and it passed all the tests.

»
16 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Why does finding diameter trivial solution still pass time limit for this test???

Test
  • »
    »
    16 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Time limit 5s is so sus in the first place

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

    because after 1 operation you have erased all nodes :fire:

    I think worst case is binary tree for D

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

    It all depends on your implementation. You first cut the path from n to n — 1. Now you are left with all single nodes.

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

    Calculating the diameter should take $$$O(n)$$$ time where $$$n$$$ is the size of the tree. First you calculate it for the entire tree taking $$$O(n)$$$ time. Now when you remove that path, you are left with $$$n-3$$$ trees which each contain a single vertex. So you calculate the diameter for each of those trees, each in $$$O(1)$$$ time for a total of $$$O(n)$$$ time once more. Now each tree is just a single path so you keep removing them and don't have to calculate any diameter.

»
16 months ago, hide # |
Rev. 3  
Vote: I like it +1 Vote: I do not like it

I am Cooked.I wasn't able to solve neither A nor B. Urgently Need to practice

»
16 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

What is wrong in my code for B it is giving WA5

void solve(){
   int n , k;cin>>n>>k;
   vi v(n);
   int mini = 1e18 , maxi = -1e18;
   fr(i,n){
      cin>>v[i];
      mini = min(mini , v[i]);
      maxi = max(maxi , v[i]);
   }
   int tot = accumulate(v.begin() , v.end() , 0);
   sort(v.begin() , v.end());
   if( (maxi - mini) <= k){
      if(tot % 2 == 1){
         cout << "Tom\n";
      }
      else{
         cout << "Jerry\n";
      }
   }
   else if((maxi - mini) == (k+1)){
      if(v[n-2] == maxi){
         cout << "Jerry\n";
      }
      else{
         if(tot % 2 == 1){
            cout << "Tom\n";
         }
         else{
            cout << "Jerry\n";
         }
      }
   }
   else{
      cout << "Jerry\n";
   }
}
»
16 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

My solution for D:

For the original tree, we find an optimal diameter and remove it from the tree. Afterward, the tree is split into several connected components, and we recursively solve the problem for each component. This process is somewhat similar to the centroid decomposition of a tree. However, I believe it is essentially a "center decomposition" of the tree.

How to compute the time complexity? We only need to consider the following problem: Given a tree T, define $$$f(T)$$$ as $$$max(f(comp[i])) + 1$$$, where $$$comp[i]$$$ are the connected components obtained by removing the diameter of $$$T$$$. An important observation is that removing the diameter of $$$T$$$ will inevitably delete the center of $$$T$$$, which ensures that the diameter of $$$comp[i]$$$ must be smaller than that of $$$T$$$. From this, we can deduce that $$$f(T)$$$ is $$$O(\sqrt(n))$$$ (for a tree $$$T$$$ satisfying $$$f(T) = i$$$, the diameter of $$$T$$$ must be $$$\ge i$$$).

I believe my implementation is $$$O(n \sqrt(n) log n)$$$, and fortunately, it passed. Unfortunately, I submitted it incorrectly multiple times.

AC code:318524754

»
16 months ago, hide # |
 
Vote: I like it +13 Vote: I do not like it

E is very cool, I like it very much! F is cool too

»
16 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

how did you guys do c?

»
16 months ago, hide # |
 
Vote: I like it -7 Vote: I do not like it

After the recent rounds Codeforces team showed that they don't care about cheaters and will not ban even super obvious ones, cheaters stopped even pretending they are not. Look at this clown's submissions: idk404, submitted multiple different codes for problem E in just few minutes, two of them are accepted. Some problems are solved in C++, some are solved in Python, but the variable names are so descriptive, surely a pro.

»
16 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Solved A,B,C within 40 min, was not able to solve D, was thinking something similar to finding diameter, but unfortunately wasn't able to implement it.

»
16 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

is there easy technique to find lexicographically largest diameter ? I did 3 traversals to achieve it .. feels not very clean.

hoping to get some code pointers from editorial.

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

    I did it using dp on trees. I rooted the tree at node 1, and for each node v I stored dp[v] = the maximum value of the pair (length of path, other end of the path), over all paths whose highest point is v. The transitions are pretty straightforward. For the final answer I just iterated over every node and looked at two highest dp values among its children and merged those two paths.

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

      oh ok, thanks... I think I need to brush up on dp on trees

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

      Once a path is selected whose highest point is $$$v$$$. DP values for all the parents of $$$v$$$ needs to be updated. Did you update those values as well?

      The number of parents whose dp values need to be updated $$$\leq d$$$. So, total number of parents that need to be updated $$$\leq n$$$ over the number of paths in the answer.

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

        I'm not updating anything. I have just shared my approach to calculate the lexicographically maximum possible diameter in O(n). When I'm deleting a diameter I'm again taking O(n) time to update for the new subtrees.

»
16 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

why this code fails for problem $$$F1$$$ ?

the code
»
16 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

What is the upper bound for time complexity for problem D?

  • »
    »
    16 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it +16 Vote: I do not like it

    I guess $$$O(N\sqrt{N}))$$$, because on every step you take path with length greater than $$$\sqrt{N}$$$, or if there is no such path, that means that tree has height less than $$$O(\sqrt {N})$$$, so you decrease height of the tree by 1. One can see that there are $$$O(\sqrt{N})$$$ such steps

    • »
      »
      »
      16 months ago, hide # ^ |
       
      Vote: I like it -17 Vote: I do not like it

      I think it's $$$O(n \log n)$$$, since each time the diameter is halved.

      • »
        »
        »
        »
        16 months ago, hide # ^ |
         
        Vote: I like it +36 Vote: I do not like it

        Not necessarily, for a tree like this:

        The diameter of the tree rooted in node 4, after taking off the bold nodes, will be 6, just two less than the original.

»
16 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can some one help me what i did wrong in this submission, My Submission.

This is the submission for problem C, but I am getting out of bound error on string s, what have i missed?

»
16 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

why am i unofficial!!! I dont see myself on the common standings unless I click show unofficial. I registered as official and I think I am a trusted participant.

»
16 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Where is the editorial?

»
16 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Great problems, thanks

»
16 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Writing From Hell because i died while debugging my own code and still not able to get where i am wrong:318542988

My approach:

1.Taking all segments where s[i]='1',and then finding max subarray sum of those segments, and storing max of all such maximum subarray sum of those segments say mx. If (mx ==k) then i set all a[i]=-1e18 such that s[i]='0' if (mx>k) then answer doesnt exist

  1. The later logic is finding the first i where s[i]='0' and then taking right[i+1,j]= max sum starting at i+1 such that all s[j]='1' and similarly left[i-1,j] where j<=i+1 and s[j]='1'.Also i stored the last indexes which were processed in left and right then for all j such that s[j]='0' && (j<lastLeft || j> lastRight) i made A[j]=-1e18.

Then returned the array.Please reply fast i am about to get deep fried here.

»
16 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

what could be the reason for a memory limit exceeded in general

»
16 months ago, hide # |
 
Vote: I like it +17 Vote: I do not like it

Congratulations to MOAQ_150 for getting top 100 trusted participant, despite being unable to solve A by himself: 318512987

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

    They also seem to have the extraordinary talent of converting 100+ lines of Python code to 200+ lines of C++ code in under two minutes! And these comments are so beautiful!

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

      I guess he was afraid of being banned because of the rule against code obfuscation and decided to document everything last minute

»
16 months ago, hide # |
 
Vote: I like it +20 Vote: I do not like it

Strange, is something wrong with CF? Look at this user uk_024

»
16 months ago, hide # |
 
Vote: I like it -14 Vote: I do not like it

Hello, I received a plagiarism warning for problem 2107A due to a match between solutions from emper0r_24 and dragon_emper0r. I would like to clarify that both accounts belong to me. I started giving contests using this(dragon_emper0r) account. But I mistakenly submitted the solution to A using the old id(emper0r_24). I did not intend to violate the rules. I apologize for the confusion and assure that it won't happen again. I’ll stick to one account from now on.

Thank you for your understanding.

»
16 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

There could have been two variants of the problem C.

Variant one : we can replace a[i] with any values till -10 ^ 18 to 10 ^ 18.

Variant two : we can replace a[i] with less than value till -10 ^ 6 to 10 ^ 6.

Does variant two make the question more difficult ?

sunkuangzheng ?

»
16 months ago, hide # |
Rev. 7  
Vote: I like it -16 Vote: I do not like it

.

»
16 months ago, hide # |
 
Vote: I like it -14 Vote: I do not like it

Dear Codeforces team,

I received a notification that my solution (ID: 318491650) for problem 2107C is similar to other submissions. I would like to clarify that I wrote my solution independently and did not share my code with anyone, nor did I copy from others.

I wrote the code locally on my personal computer using IntelliJ IDEA and did not use any online compilers, public repositories, or code-sharing platforms during the contest. I also did not discuss or share my solution with anyone.

Please let me know if there’s any further information I can provide to clarify this situation. Thank you for your time and understanding.

»
16 months ago, hide # |
Rev. 4  
Vote: I like it 0 Vote: I do not like it

unforgettablepl congrats darling :D

»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Good luck to conqueror_of_tourist on his mission