xoxo's blog

By xoxo, 4 months ago, translation, In English

Hello, Codeforces!

We are glad to invite you to participate in Codeforces Round 1099 (Div. 2), which will be help on May/21/2026 17:35 (Moscow time). You will be given of 6 problems and 2 hours to solve them. This round will be rated for the participants with a rating lower than 2100.

The problems are authored and prepared by xoxo, Kuyan, FairyWinx, sunkuangzheng, TheScrasse and Vladithur. Also, we want to express our sincere thank to people without whom this round would be impossible:

The scoring distribution will be published later.

We hope you enjoy the round. Good Luck and Have Fun!

UPD. The scoring distribution will be as follows: $$$500 – 1000 – 1250 – 2000 – 2500 – 2750$$$

UPD: Editorial

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

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

Auto comment: topic has been updated by xoxo (previous revision, new revision, compare).

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

As a linger fan, I will sleep early this round.

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

Wow unexpectedly short announcement.

Hope the contest proceeds well!

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

very excitedd

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

Excited for the contest! All the best everyone!

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

As a newbie, I hope my code is shorter than this announcement.

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

xoxo i think you have wrote help in the announcement by mistake it should be held right ??

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

    Yes, you got it right. The letter d just accidentally rotated itself mid-typing. Thanks!

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

As a participant, how to be a tester?

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

    they may have private groups to discuss and organize contests and let people who have free time to test

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

    Back in 2019 I once randomly got a message in CF from MikeMirzayanov asking if I would be available to test a round. Not sure if they still use this approach to recruit testers.

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

How clever of Makka-Pakka

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

hope to have some good conceptual questions not like previous edu round 190

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

Hope that the statements will be as short as the announcement

»
4 months ago, hide # |
 
Vote: I like it -27 Vote: I do not like it
»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I love participating in DIV. 2

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

My first Div2 Send luck

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

Hope reach CM

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

help or held //

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

xoxo Could you add the score distribution?

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

Please add the score distribution.

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

Auto comment: topic has been updated by xoxo (previous revision, new revision, compare).

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

The rise in points from C to D is (+750), crazy!!

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

This is my first CP contest ever, wish me luck folks!

»
4 months ago, hide # |
 
Vote: I like it +9 Vote: I do not like it

Why do I have to complete a CAPTCHA for every submission I make, and it keeps failing to verify?

Isn't this a bit unreasonable? It will make me lose a lot of points for nothing.

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

$$$D$$$ was a good problem, thanks for the round!

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

Why 2231B - Another Sorting Problem is a problem B and 2231C - Chipmunk Theo and Equality appears in Codeforces round.

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

    I swear I've solved C on Leetcode 2-3 years back, just can't pinpoint which problem was it. Anyone remembers?

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

Hints

A. Construct an Array

Hint 1
Hint 2
Solution

B. Another Sorting Problem

Hint 1
Hint 2
Hint 3
Hint 3
Hint 3
Hint 3
Hint 3

C. Chipmunk Theo and Equality

Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Hint 6
  • »
    »
    4 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    My O(n∗Log2(n)^2) approach wasn't working,try multiple possible O(n∗Log2(n)^2) soln,every soln leads to tle,idk why :(

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

      worked for me .. direct simulation

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

        can you please share your code,I can't open submission.

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

          ok .. code is at the bottom .. sorry for bad names in code

          main idea is to iterate on all candidates, all candidates are values which we can reach from minimum value

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

            what i did store all values which each number can reach untill it becomes 2 and update in map if any value is ==n in map then that is the contendor then iterate over vector and compute ur ans and take min but this time compl is o(n*n*log(max(v[i]))) still it got accepted https://codeforces.me/contest/2231/submission/375530544

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

              whoa LOLOLOL !!!

              my guess is somehow this line if (it.second == n) is pruning a lot of values .. but can't prove it

              also in some cases we have value 1 which we need to convert to 2 .. not sure how it is handled in your code .. maybe mp[2] does it

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

                but how one can guess pruning thing will it happen or not here atleast we are iterating over number of elements in vector so we get o(1e5) * smthing this smthing is dependent on vector + while loop how can i guess or show it is not quadratic

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

                  I find it not easy to strictly analyze .. but idea I am getting is if all numbers are different then values which have mp[v] == n will be less

                  like 2 different element can have at max ~30 common values, so I guess you might not be getting too many values for which inner loop is executing.

                  is this essentially same as taking only one element and going through its possible final states

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

      Ohh , I too thought this could be best complexity,like a trie format , ..was gonna try post contest..

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

      because, map has higher constant than 2

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

        oh didn't knew that,Thanks bro!

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

          I didn't look at your code, but it seems that you used map or unordered map. My solution was O(n*log(max(a[i])) with a unordered map and it exceeded the time limit. I submitted another solution later without using unordered map and with a same time complexity and it passed. Therefore I guess it's the map's problem (map has a high constant)

»
4 months ago, hide # |
 
Vote: I like it +40 Vote: I do not like it

In problem C, why it is a[i] <= 1e9 not a[i] <= n

Getting TLE because of map doesn't make sense to me

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

    +1

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

    how did you use map in it ?

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

      I didn't, I made a vector of pairs and sorted them (a retarded map if you ask me)

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

        oh wow !! looks like n logn logn, should pass ... I guess sorting such big array might be slow... can you please try arr.reserve(n * 32) ..so that I know it is not because of push_back

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

          I believe this suggestion will make the code faster, and I'll add write arr.reserve(n * 64) not arr.reserve(n * 32) because a[i] can go up to 1e9 (log base 2 of it is 32, and we may add one every time we divide, so 32 * 2 = 64)

  • »
    »
    4 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it -22 Vote: I do not like it

    Because main part of this problem — write optimal code, because you use map with size nlog And this is too slow

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

    In map u need to use map<pair<int,int>,int> pair cuz u need to store a[i] and the value u choose to make it .. i ignored duplicates and didnt use map cuz atmost operations are 3.5x10^8 <2sec but using map optimizes the code

»
4 months ago, hide # |
 
Vote: I like it -8 Vote: I do not like it

i loved this round thank you!

»
4 months ago, hide # |
 
Vote: I like it +116 Vote: I do not like it

On the problem statement of E.

He became interested in how many different such subgraphs he can cut out. Subgraphs are considered different if the chosen triples of vertices are different.

Even though the second sentence adds a clarification, I think these two sentences are completely contradictory. I believe it would have been better to state this accurately from the beginning, for example: "Count the number of triples such that ..."

I do not think an inaccurate problem statement should be considered acceptable merely because a clarification is added afterward. At the very least, a problem statement should be written so that most readers can understand it naturally in the intended way.

For example, I think everyone would agree that a statement such as "Find the sum of A_i. Here, in this problem, sum means product" is clearly inappropriate. This problem statement felt similar to that to me.

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

    100% Agree. Not only that, but the samples also don't clarify that. I had to write stress-tests for my WA2 solution, pass stress tests, get wrong answer and only then see that the problem asks for something clearly different. And the triplet part doesn't even contribute to the problem in a meaningful way, it's effectively the same with the subgraphs.

»
4 months ago, hide # |
 
Vote: I like it +30 Vote: I do not like it

Feedback:

  • A: nice
  • B: nice
  • C: I don't understand why the TL is so low (assuming that the intended solution is O(n * 60 * hashmap)). OK problem.
  • D: I don't like this problem at all, the idea is simple and yet the implementation can be terrible if one isn't careful.
  • E: I like it, but it is perhaps a bit too standard for a non-edu round in 2026?
  • »
    »
    4 months ago, hide # ^ |
     
    Vote: I like it +8 Vote: I do not like it

    C shouldn't return a TLE because of map but sadly the limit was an overkill

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

    For problem E did you use fft or something to calculate the convolution or did you not have to calculate it at all?

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

      It's a straightforward application of trick 7 from this blog.

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

      I thought of this during contest and finally got it working afterwards, 375580994

      The path test case kept TLE-ing me so I added a special case for 1 child, which passed. I can't tell if the test cases have one that's a path of length 1000, each node having 1 other child, which might mess up this simple optimization, but I don't know how to check this (could also add a children[u] = 2 edge case then)

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

    i don't think the intended solution for c involved using hashmaps i simply bruteforced it

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

    u can simply iterate over all possible values the minimum value of the array can be converted to

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

    In C i mean the observation that the numbers must be equal to a number that can be reached from the minimum is the most important part, no matter how it is implemented

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

      Not really. Minima is not special. If you pick any number $$$a[i]$$$ in the array, then you can claim that the final answer lies on the path this element takes. Taking minima produces $$$O(log(n))$$$ candidates, but taking any random elements also produces $$$O(log(n))$$$ candidates.

      You can go one step further and say that any 2 numbers $$$x$$$ and $$$y$$$ have a unique meeting point (with the exception of $$$1$$$ and $$$2$$$). Therefore, the entire array has a unique meeting point, so there are only 2 candidates, and not $$$O(log(n))$$$ candidates.

      Submission with $$$O(n \cdot log(n))$$$ time complexity.

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

    could'nt agree with D, easy implementation

    In c hashmap was not required.

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

solved

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

bad C

Why does it force me to write a discretization?

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

Just tried to brute force C and it passed Is that the optimal solution?

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

    how did you find what values final equalized value can take ?

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

      The way I checked was if high== low high-> largest element and low -> lowest element Then answer is done If high=low+1 and high is divisible by 2 the final value will be high( high=2 and low=1 is edge case handle separately ) Any other case just implementthe algo on high

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

    Depends on your brute force. It takes O (log N) steps for a number to reach 1 or 2. So in my head, a good brute force approach should work.

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

      yeah it worked, like storing all reachable positions (log(maxA[i]) then iterating over them and updating simultaneously. It gave me TLE on 20 th case but later on when i changed long long to int, it passed the test cases.

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

    There's no need to do that, there's a simpler approach:

    1. Notice that any a[i] only decreases. It follows that at each step we must decrease the i-th number.

    2. For optimization, we can use a map.

    3. Edge case: when the map size is 2, the answer will be count(x — 1) if x == 0 mod 2 and x != 2, and when x == 2 the answer will be min(count(x), count(x — 1))

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

In C, if we take only the first 2 numbers in the operation sequence of least element which also are in the operation sequence of all numbers, why won't testing them be sufficient to find the minimum answer?

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

    Sounds like it should work.

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

      void solve() { int n ; cin>>n; iv(v,n); sort(all(v)); ll a=v[0]; ll b=v[0]+1; ll c=v[0]-1; ll ans=0; ll ans2=0; ll ans3=0; f(i,n){ ll h=v[i]; map<ll,ll>mpp; while(h>=a-1&&h>0){ mpp[h]=1; if(h==a){ break; } if(h%2==0){ h=h/2; if(mpp.find(h)!=mpp.end()){ break; ans=INF; } } else{ h=h+1; if(mpp.find(h)!=mpp.end()){ break; ans=INF; } } ans++; } } f(i,n){ ll h=v[i]; map<ll,ll>mpp; while(h>=b-1&&h>0){ mpp[h]=1; if(h==b){ break; } if(h%2==0){ h=h/2; if(mpp.find(h)!=mpp.end()){ break; ans2=INF; } } else{ h=h+1; if(mpp.find(h)!=mpp.end()){ break; ans2=INF; } } ans2++; } } ll ans4=min(ans,ans2); cout<<ans4<<endl; }

      i did the same thing but it didnt pass 375551055

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

    #include <bits/stdc++.h> using namespace std; #define int long long using ll = long long; using pii = pair<int,int>; using vi = vector<int>; using vll = vector<long long>; #define pb push_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define rep(i,a,b) for(int i=(a); i<(b); ++i) #define repn(i,n) for(int i=0; i<(n); ++i) const int INF = 1e18; const int MOD = 1e9 + 7; /* ======================================== Problem Statement ======================================== pass hoja pls ======================================== */ /* gx = (x+1)/2 cx = 1 + x mod2 fx< x it converges at t ? commong convergence point for all total cost = sig(i =1 )^n s(ai, k t ) c(s) at the end 1 and 2 ? at 1 min of both 1 and 2 sum > ? x = m.2^v2(x) v2(x/2)=v2(x)-1 v2(x+1)>=1 ???????? */ int f(int tgt,int n , vector<int> &a){ int kl = 0 ; repn(i,n){ int ct = a[i]; if(tgt==2 && ct==1){ kl++; continue ; } while(ct>tgt){ kl+=1 + (ct%2); ct = (ct+1)/2; } } return kl; } void solve() { int n ;cin>>n; vi a(n) ; for(int i =0 ; i <n ;i++)cin>>a[i]; vector<pair<int,int>> cands ; int ct = a[0] , kl = 0 ; while(ct>1){ if(ct%2 ==0 ){ while(ct%2==0){ cands.pb({ct,kl}); ct/=2; kl++; } }else { cands.pb({ct,kl}); ct++; kl++; } } cands.pb({1,kl}); if(a[0] == 1) cands.pb({2,1}); for(int i =1 ;i < n;i++){ vector<pair<int,int>> curr_path; ct = a[i]; kl = 0 ; while(ct>1) { if(ct%2==0) { while (ct % 2 == 0) { curr_path.push_back({ct, kl}); ct/=2; kl++; } } else { curr_path.push_back({ct, kl}); ct++; kl++; } } curr_path.pb({1,kl}); if(a[i] == 1) curr_path.pb({2,1}); vector<pair<int,int>> next_cands; for(auto & cand: cands){ for(auto &cp: curr_path){ if(cand.first ==cp.first){ next_cands.pb({cand.first,cand.second+cp.second}); break; } } } cands = next_cands; } int ans = INF; for(auto cand:cands){ ans = min(ans,cand.second); } cout<<ans<<endl; } int32_t main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t = 1; cin >> t; while (t--) solve(); return 0; }

    i did this for c i am not really sure if its optimal tho i am basically tryna simulate paths from every number down to 1

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

tricky B for me ... I got idea for C quickly but you have to code it in fast way.

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

    For problems like $$$B$$$, I always visualize them as mountains with peaks at height $$$a_i$$$, and you can think of the operation as "lifting the mountains up". So when $$$i-1$$$th mountain is taller than $$$i$$$, we need to lift the $$$i$$$ th mountain by atleast $$$a_{i-1} - a_i$$$. This visualization always helps me solve such problems.

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

      I was confused about what happen to next element of the element we pick up, as we add 'k' to all elements... what if that becomes larger than next element ... so I was not sure of correctness.

      although because now pretest = main test, I just submit my random ideas as I can verify it fully

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

Dude I was so fed up of C I had to rewrite my whole Java code into C++ for it to be accepted.

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

    did it accpeted?

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

    I did lots of optimisation for my java code , i am precomputing min distance still it is getting TLE like why? `int t = sc.nextInt();` ` while (t-- > 0) {` ` int n = sc.nextInt();` long a[]=new long[n]; ` Map<Long, Integer>map=new HashMap<>();` for(int i=0;i<n;i++){ a[i]=sc.nextLong(); } Map<Long, Long>mp=new HashMap<>(); long ans=Long.MAX_VALUE; ` for(int i=0;i<n;i++){` long temp=a[i]; ` Set<Long> set=new HashSet<>();` map.merge(temp, 1, (x, y)->x+y); ` long it=0;` set.add(temp); ` mp.merge(temp, it, (x, y)->x+y);` if(map.get(temp)==n){ ans=Math.min(ans, mp.get(temp)); } while(true){ if(temp%2==0){ temp=temp/2; }else{ temp++; } ` if(set.contains(temp))break;` map.merge(temp, 1, (x, y)->x+y); it++; ` set.add(temp);` mp.merge(temp, it, (x, y)->x+y); ` if(map.get(temp)==n){` ` ans=Math.min(ans, mp.get(temp));` ` }` ` }` ` ` } ``

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

    For C:- I am trying to understand why this Java solution gets TLE.

    Idea:

    For each number, I generate all reachable values using:

    • even → x/2
    • odd → x+1

    I maintain:

    • map[value] = number of elements that can reach value
    • mp[value] = cumulative operations needed to reach value

    So I am not recomputing distances; I accumulate them while traversing.

    Whenever map[value] == n, that value becomes a candidate answer.

    Code:https://codeforces.me/contest/2231/submission/375593971

    Expected complexity:

    • Each number follows a single chain
    • Chain length should be around O(log ai)
    • sum(n) ≤ 1e5

    So I expected roughly O(n log A).

    Is the TLE mainly due to:

    • HashMap.merge() overhead?
    • Creating HashSet for each element?
    • Long boxing/unboxing?
    • Some hidden complexity I am missing?

    I want to understand the exact reason for TLE rather than replacing the approach.

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

    hash collision & the constant is too big

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

    try using just one unordered_map, passed for me in around 1700 ms unordered_map<ll, pair<ll, ll>> where you store the frequency and count

    And i guess there are no test cases where extreme collisions happen

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

      Thanks a lot! Turns out I just had to use an unordered_map because of the large constant, and got AC immediately after... I was scared to use unordered_map due to to the risk of rehashing.

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

what's the approach for problem B..? :(

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

Why does my O(n log^2 n) solution for problem C get TLE on test 4?

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

    https://codeforces.me/contest/2231/submission/375542810

    I think I same with you. I also TLE on problem C I don't know why

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

    Because appeal to map (unordered too) with size 5e6 is too slow, and if you store only numbers, which from proccess for the first element — it will be work fast

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

      can I see your solution?

      • »
        »
        »
        »
        4 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it
        from collections import Counter
         
        for _ in range(int(input())):
            n = int(input())
            a = list(map(int, input().split()))
            cnt1 = dict()
            cnt2 = dict()
            x = a[0]
            a = a[1:]
            s = set()
            c = 0
            while x not in s:
                if x not in cnt1:
                    cnt1[x] = 0
                if x not in cnt2:
                    cnt2[x] = 0
                cnt1[x] += 1
                cnt2[x] += c
                s.add(x)
                if x & 1:
                    x += 1
                else:
                    x >>= 1
                c += 1
            for x in a:
                s = set()
                c = 0
                while x not in s:
                    if x in cnt1:
                        cnt1[x] += 1
                        cnt2[x] += c
                    s.add(x)
                    if x & 1:
                        x += 1
                    else:
                        x >>= 1
                    c += 1
            ans = 10 ** 18
            for k, v in cnt1.items():
                if v == n:
                    ans = min(ans, cnt2[k])
            print(ans)
        
        
»
4 months ago, hide # |
 
Vote: I like it +12 Vote: I do not like it

thank you cf, had a good time.

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

Problem E: Did anyone try small to large optimization with a twist that "small" and "large" is on heights? Did it pass the TL?

I assume it should be $$$O(n)$$$ per DFS, and running from every possible root you get $$$O(n^2)$$$, but it doesn't pass for me, unsure why. 375550780

If that's not the solution, what's the good straightforward alternative? For me the small to large seemed like the most straightforward approach: split answers in two- and three-ways, two-ways are trivial, and for three-ways we need to combine two depths from center vertex => small to large.

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

    "For me the small to large" all this solutions work (that i know) in O(n^2) with naive merge, because you any pair of vertex calculate only in their LCA

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

      The idea is not exactly this one, it's a fair small to large, and the swapping is important.

      The idea is that if for $$$v$$$ you have two subtrees, one of depth $$$A$$$ and another of $$$B \lt A$$$, and you combine them in $$$O(B)$$$, the B becomes hidden in the combinator result that has size A. And because depth B requires B vertices, you can estimate by coin method the amortized $$$O(n)$$$.

      That's a cool technique tht I use once in a while, and I can't understand why it failed me here.

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

        Yeah, it works, i just got destroyed in too many small allocations for vectors, had to pre-allocate them 375573721

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

    I did do the $$$ O(n) $$$ small to large, but I didn't run it from every root, I did one dfs, with $$$ O(n^2) $$$ dp: 375530382

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

    I had same idea, and my solution pass. 375531942

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

    Hi, I did small to large sort of. My AC implementation is here: https://codeforces.me/contest/2231/submission/375566090

    I broke it down as follows:

    Any group of 3 nodes either forms a simple path, or a Y-shape.

    For simple paths we have two cases: -The LCA of all 3 nodes is one of the three nodes -The LCA of all 3 nodes is a different node

    We could solve these separately or together in many ways.

    The Y-shaped cases are more interesting: For a Y-shape, the LCA of all 3 nodes is not one of the three nodes. call this LCA L.

    We could have all three nodes come from different children's subtrees of L. We could also have two nodes come from one child's subtree of L, and the third node comes from a different child's subtree.

    This is the part I used small to large merging for. For each node we treat it as an L. I want to know how many nodes in L's subtree have a distance of X, and how many pairs of nodes have a distance of X. We can aggregate these together in the merging process to update the result.

    I think I probably did not do it the cleanest way, but I used the standard "offset" trick where each node stores an unordered map and when we bubble up we shift the offset by 1.

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

The "Time limit exceeded on pretest 4" of problem C killed me. Good Bye candidate master and Hello expert !

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

Failing D on pretest 2, could not figure out at all

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

Can someone please help me with any counterexample to my code for problem B of this contest? I can't see what's wrong here... Please ignore the bad formatting, I've added comments so that I can explain what I'm trying to do

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

    I was doing something similar to you initially..try this test case

    1
    5
    2 1 2 4 2
    

    It's answer is yes(choose index $$$ 2, 3, 5$$$ and increase them by 2) Hope it helps

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

Can someone please help me with D??

I was able to find out two conditions that's it —

  1. If value in the c array changes during a forward pass (c[i] < c[i+1]) then b[i+1] = c[i+1]
  2. a[0]=c[0]

How to proceed from here?? Thank You.

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

    So we can maintain a visited array v. For all i, v[i] is set to 1 if we know the value of b[i], otherwise we set it to 0. So using your first condition, we can set v[i+1] to 1, whenever c[i]<c[i+1], since we know what b[i+1] is. Also b[0]=a[0]

    Now we iterate from right to left(i=n-1 to i=1). If for some i, v[i]=1 (which means we know b[i]) and a[i] as well, then b[i-1]=b[i]-a[i-1], and therefore we know the value of b[i-1] as well, and we can set v[i-1] to 1. In the other case, if both v[i-1] and v[i] is 1, then we know both b[i] and b[i-1], and therefore, a[i]=b[i]-b[i-1], and we set set s[i] to '1'. In the case, that we know all a[i],b[i] and b[i-1], we just check if a[i]=b[i-1]-b[i], if this condition does not hold, there exists no valid construction

    So now, we will iterate from left to right. For each i from 1 to n-1, we will make 4 cases:-

    Case-1 s[i]='0', and v[i]=0, we just set a[i] to some negative number of large magnitude, and update b[i]=b[i-1]+a[i]

    Case-2 s[i]='0', and v[i]=1, we know b[i] but not a[i], we set a[i]=b[i]-b[i-1]

    Case-3 s[i]='1' and v[i]=0, we know a[i], but not b[i], so we set b[i]=b[i-1]+a[i]

    Case-4, s[i]='1' and v[i]='1', we don't need to do anything since both a[i] and b[i] are known

    Clearly at any i, we know a[j] and b[j] for all j from 0 to i-1, due to the nature of the construction, hence all updates to a[i] and b[i] will be correct.

    So why is it so important to set a[i] to a large magnitude negative number in case-1. This is because if there are large known a[j], and you use say, a[i]=-1, for some j>i, b[j] could exceed c[j].

    As a final step, you just check if you construction violates any constraints (either a[i] or c[i]). If it does, then there exists no other construction, and if it doesn't you can just print your construction. For more clarity regarding this why this step is required, check sample test case-6

    Of course, the above paragraph also works as proof of correctness of the construction

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

D was a nice implementation problem.

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

MikeMirzayanov Please allow unofficial participation of contest like atcoder. 😭 😭

»
4 months ago, hide # |
 
Vote: I like it -8 Vote: I do not like it

ConstrumentationForces

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

In C , My code 375545444 got accepted without using Hash map. Why using Hash map ? is it creates any big difference here?

»
4 months ago, hide # |
 
Vote: I like it +11 Vote: I do not like it

Pretty good contest, it would be better if the TL of problem C were larger.

Anyway, I'm glad to reach CM again in this round, especially on my birthday.

This is a wonderful birthday gift for me!

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

well, C will come in my nightmares now, thank you very much

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

such a great contest ! is there an editorial .

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

Very good contest!

»
4 months ago, hide # |
 
Vote: I like it +11 Vote: I do not like it

Problem C was really fun! I found an $$$\mathcal{O}(\sum \log a_i)$$$ solution that doesn't use data structures at all: 375569790.

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

    did something similar, but i overcomplicated it too much using multiset+map :p

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

      Right, lots of people did something along those lines, but the multiset/map adds an $$$\mathcal{O}(\log n)$$$ factor to the time complexity for a total of $$$\mathcal{O}(\log n × \sum \log a_i)$$$ which sometimes causes a timeout.

      And of course, there are solutions that use a dictionary/hash map instead of an ordered map. This is faster and theoretically even O(1), but this O(1) still adds a significant overhead in practice.

      I wanted to share a solution that is strictly $$$\mathcal{O}(\sum \log a_i)$$$ without any overhead from data structures.

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

    Awesome solution! just did a cpp implementation of your idea : 375604689

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

FOR C I DID LIKE THIS PLEASE GIVE A LOOK :)

I first sorted the array.

Observation: the final array must become some value lying on the path of the smallest element. Example: for 3,4,5, path of 3 is:

3 -> 4 -> 2 -> 1

So possible final values are {3,4,2,1}.

For every candidate p from this path, I calculate total operations needed to convert every element a into p.

Example for p = 2:

  • 3 -> 4 -> 2 = 2 steps
  • 4 -> 2 = 1 step
  • 5 -> 6 -> 3 -> 4 -> 2 = 4 steps

Total = 7 steps.

To compute steps for one element:

while(a != p){
    if(a & 1) a++, steps++;
    else a /= 2, steps++;
}

Trap: for p = 3 and a = 4:

4 -> 2 -> 1 -> 2 -> 1...

This becomes infinite because after going below p, reaching p again is impossible.

So during division, if p - a >= 2, I return a large value (1e5) so that candidate p is ignored.

Complexity:

  • Candidate generation: O(log Amax)
  • Array traversal: O(n)
  • Conversion per element: O(log Amax)

Overall: O(n * log²(Amax)). WHERE AM I WRONG :)

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

Editorial?

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

I hate TLE on test 4.

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

Where is the editorial ?

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

Editorial please?

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

No editorial even after 12 hours of the contest, bad !!!!

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

for each i perform abi:=abi+k Doesn't it mean that those b subsequence are indexes of array a Or i am interpreting the question wrong?

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

EDITORIAL?

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

where i can see the edutorials,tutorials,solutions ?

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

A good extension of question B is to find the number of valid k

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

has the editorial been released

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

When is the editorial going to be published

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

Where is editorial?

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

Here's my solution for problems A-C (sorry for bad explanation?)

Problem A
Problem B
Problem C
  • »
    »
    4 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Hi, my approach to problem B looks similar to your solution. Can you help me identify where my algorithm is wrong ? I am getting WA on test 2.

    Submission Link — https://codeforces.me/contest/2231/submission/375505094

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

      I fixed it a little bit:

      • Updating prefMax in the if condition (line 19 in the fixed submission)

      • Incrementing a[i] if its unmarked and is less than the previous value (lines 33 and 34)

      Here's the fixed submission 375652032

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

        Thanks for correcting my code!

        I found out that the main issue was that I was not updating the elements that were not marked. But that could be needed if after incrementing the current element it becomes greater than the next element which was earlier not smaller than than the prevMax.

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

I used map in problem C why it takes TLE ?

my code
»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Drop the Editorial please

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

whens the editorial up?

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

Auto comment: topic has been updated by FairyWinx (previous revision, new revision, compare).

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

Recieved a mail regarding solution coinciding. I am not sure how do you find those solutions same and from my side no cheating took place. Pl[submission:375526933]ease look into this. This was my submission 375526933 And the violated one has http://contest/2231/submission/375517996

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

editorial pls.

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

I did not intentionally copy any code. I wrote the solution myself during the contest. The approach for this problem was common, so the solutions may look similar. I will be more careful in future contests. Thank you.

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

Just received a notification stating that ratings for the last rounds have been temporarily rolled back. Can anyone educate me on what that means?

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

Dear, organizers.

I would like to clarify the situation regarding my solution (submission:375528371) for problem 2231F.

Near the end of the contest, under time pressure, my friend and I used AI-generated code assistance for problem F and submitted the solution without properly thinking through the consequences or the contest rules. Shortly afterward, we realized that this was inappropriate and violated the competition rules regarding external assistance.

We take full responsibility for this mistake. There was no intention to collaborate with other contestants or deliberately abuse the system, but we understand that using AI-generated code during a rated contest is unfair and against the rules.

We sincerely apologize to the organizers and the community for this behavior. We fully accept any decision regarding disqualification, rating rollback, or other penalties.

This was our mistake, and we will make sure not to repeat it in future contests.

Thank you for your understanding.

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

Dear Organizers,

I am writing to appeal the decision regarding my solution (submission ID: 375501684) for problem 2231C, which was flagged for coinciding with other solutions. I fully respect the integrity of the platform and the necessity of plagiarism detection. However, I believe my case is a false positive caused by the problem's limited solution space and the natural convergence of optimal coding patterns.

I would like to detail my development process, supported by the actual code I wrote, to demonstrate that my solution is the result of independent debugging and optimization.

My first submission(id:375495165) used unordered_map to track the total steps (to) and count (c) for each reachable value. The logic involved simulating the process for each starting number and storing results in hash maps. This approach was intuitive but resulted in a Time Limit Exceeded error due to the overhead of hash operations and the complexity of the simulation.

After identifying the performance bottleneck, I redesigned the algorithm. Instead of using hash maps, I switched to a vector of pairs (value, steps). I collected all reachable states for each starting number, then sorted the vector and aggregated steps for each unique value. This eliminated hash collisions and improved cache efficiency, leading to a successful submission.

Furthermore, this contest is of utmost importance to me — it is, without exaggeration, the best performance I have ever achieved in my entire life. I sincerely hope that it will not be unjustly invalidated due to a false positive in the similarity detection.

I fully support Codeforces' anti-cheating measures and understand the need for automated detection. However, I respectfully request a manual review of my submission history, which clearly shows the evolution from a TLE solution to an optimized one. This pattern is inconsistent with code copying.

I am confident that a thorough review will confirm my innocence. Thank you for your time and for maintaining such a fair and competitive platform.

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

Hello,

I received a coincidence warning for my submission 375528547 for problem 2231E. I would like to clarify that I solved the problem independently and did not intentionally copy any code.

The solution uses standard competitive programming techniques and common approaches that are widely available in public resources and Codeforces blogs before the contest. Because of this, some structural similarity between solutions may naturally occur.

I did not share my code publicly during the contest and was not involved in any intentional plagiarism or leakage.

I respectfully request you to reconsider my submission.

Thank you.

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

    Dear Codeforces Team,

    I would like to kindly follow up regarding my previous appeal about the coincidence warning issued for my submission 375528547 on problem 2231E.

    I understand that the review process may take time, but I would be grateful if you could reconsider my case when convenient.

    As mentioned in my earlier message, I solved the problem independently and did not intentionally copy any code. The solution is based on standard competitive programming techniques and common approaches that were publicly known before the contest, which may naturally lead to similarities between submissions.

    I did not share my code during the contest and was not involved in any plagiarism or information leakage.

    I respectfully request a review of my submission and would appreciate any update regarding the status of my appeal.

    Thank you for your time and consideration.

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

C was good tbh!!!