Gellyfish's blog

By Gellyfish, 4 weeks ago, In English

Hello, Codeforces!

I'm pleased to invite you to Codeforces Round 1028 (Div. 1) and Codeforces Round 1028 (Div. 2). It starts on May/31/2025 17:35 (Moscow time). This means that Children's Day will come during this round. I'm sure everyone will be impressed with Children's Day, even if they're no longer children.

I remember when I was a kid, I always looked forward to Children's Day. On Children's Day, there were always candies and fun activities at school. But as I grew up, this festive atmosphere was diluted by the trivialities of life. But luckily, we had Codeforces. Spending the holidays with interesting problems doesn't actually have to be more boring than candies and activities ¯\_(ツ)_/¯

This will be the second round I've hosted on Codeforces. To make it better, this time I've called on my friend MagicalFlower to help me organize this round. Also, errorgorn has helped us very much, we are fully indebted to this well known 🐸 on Codeforces!

For both divisions, you will have 2 hours to solve 6 problems. I hope you will enjoy these problems.

I would like to thank:

Especially, I'd like to thank JoesSR, zhaohaikun and ToxicPie9 for helping us prepare this round, which might not be able to run as smoothly as now without them.

Finally, I would like to give my heartfelt thanks and praise to errorgorn.

Both of the rounds I hosted would not have been possible without the support and efforts of errorgorn. Although he often rejected my problems 💀 and stood me up a lot 😡, I could sense his love for the problems and his seriousness about the competition in the time we spent together preparing for these rounds.

errorgorn is an interesting guy, you can often see him sending funny emoji like 🤯 in the discord, and he would also sometimes share me with some of the local culture of Singapore. I am so lucky to have had this fun time with him.

Some time ago, errorgorn happened to tell me that he might not have time to continue as Coordinator, which I deeply regretted. Likewise, I'm starting my college career, and this will probably be the last round I host at Codeforces as well.

Hopefully this round will be a perfect end to my experience hosting rounds on Codeforces. It's really quite an unforgettable experience, and I'm also looking forward to the next collaboration with errorgorn.

The main character of the problems will be Gellyfish🍏, and her friend Flower🌸.

Score distribution:

  • Div.1: $$$500-1250-1750-2250-3000-(2500-3500)$$$
  • Div.2: $$$500-750-1250-2000-2500-3000$$$

Good Luck & Have Fun! 🔥🔥🔥

UPD1: Congratulations to the winners!

first solves in Div.1
first solves in Div.2

UPD2: Editorial is out.

  • Vote: I like it
  • -197
  • Vote: I do not like it

»
4 weeks ago, hide # |
 
Vote: I like it -50 Vote: I do not like it

hope to solved at least 2 or better 3 problems. GL

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

Sorry guys, errorgorn can't coordinate anymore. He's busy coordinating dates with me 😳

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

I aim to reach pupil in this round ,and solve at least 3 problems

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

As a tester, I hereby strongly recommend Frieren: Beyond Journey's End (葬送のフリーレン).

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

Hope to solve 3 questions for the first time in a div2.

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

This is my first contest as a specialist!

»
4 weeks ago, hide # |
Rev. 3  
Vote: I like it -23 Vote: I do not like it

good luck

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

Appreciate the effort—looking forward to the contest!, and good luck with your college career.

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

Hoping that problems will be very easy

»
4 weeks ago, hide # |
Rev. 2  
Vote: I like it -10 Vote: I do not like it

Hopefully it's going to be a fun game :D

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

Feeling your love for errorgorn — is this a record for 'how many times someone is mentioned in a round announcement'?

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

hope to solve three in 20-30 and then grind on 4th

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

As a tester,I think these problems are brilliant and I hope you find them enjoyable.

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

Whenever I try to use emoji, it says:
Emoji (and other unusual UTF-8 characters) are not supported :|

And this guy filled the blog with emojis.(¬_¬)

»
4 weeks ago, hide # |
 
Vote: I like it -10 Vote: I do not like it

Use no emojis in these blogs.

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

hope to solve 3 problems and get +delta

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

hope to be green again!!

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

errorgorn is a interesting guy

a -> an

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

I'm literally 1 rating away from participating in Div 1 XD

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

It should be "is an interesting guy" ig, on the last 4th paragraph.

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

As a tester,I hope you enjoy this contest :)

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

It’s really sad to hear that this will be your last round as a coordinator =(( Thank you for all the effort and passion you’ve poured into preparing such fun and thoughtful problems. Even if you won’t be hosting rounds anymore, I hope you’ll stay connected with the Codeforces community in some way. Wishing you all the best in your next chapter!

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

Happy Children's Day ;-)

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

hope to solve 2 questions for the first time in Div-2

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

all the best to everyone

»
4 weeks ago, hide # |
 
Vote: I like it -10 Vote: I do not like it

I will crashing the round gg

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

Hope to not get wrong on first 3 submission

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

I have been losing ratings in the past 3 rounds. Hopefully, this pattern will change today :)

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

I miss my childhood

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

I will never be a contester in any contests of THU qwq

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

Wasn't div2C/div1A a simple wrapper over https://codeforces.com/contest/1043/problem/F ?

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

    i solved it using DP with time complexity O(n * max(a) * gcd)

    would be time limit exceeded on the problem you shared (I haven't solved it)

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

Problem 2 can be done in O(n) ig, premax of indices and max of biggest index in p and q (also their respective index :( in case of equal)

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

    322280690 Can you tell me where i have failed on tc-3

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

      Same

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

      @shviv1 I think you have not taken the case where for example :

      We have been given : p : 5 8 9 3 4 0 2 7 1 6 q : 9 5 1 4 0 3 2 8 7 6 I will be considering 0 based indexes. So the common initial logic here must be to store the maximum among the array p or q as we loop through and at each index i we print according to the maximum we have but there is another case which we have to consider which I think you might not have :

      Considering the above test case , at the index 3 we have max in p = 9 and max in q = 9, both are same so we have to check the corresponding values in q wrt to p and in p wrt to q and we have to print the max among them . Ypu can check if your code is following this strictly.

      My code : 322233429

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

      in this problem even I failed at tc-3, later I realized that we are comparing the
      two possible solutions after taking mod. what I am trying to tell is if p%mod > q%mod, that doesn't mean that p > q, so directly compare to what power you are calculating and then calculate the power_mod and output accordingly. By the way, I got so frustrated after realizing this simple thing after the contest

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

    my first solution (using this fact) TLed for some reason(maybe because I used python idk)

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

    binary exponentiation cost logn for each operation

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

      but I was storing them with mod,is it still logN? two[0] = 1; for(int i=1;i<n;i++) two[i] = ( 2 % mod * two[i-1] % mod) % mod;

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

The time limit on C was surprisingly tight. Tried to do 2d caching for a while before I realized the second dimension was unnecessary.

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

Getting Destroyed by testcase 3 on problem D for an hour and a half crew. Fun problems, thanks!

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

WA on pretest 9 in C?

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

BurnedChicken What happened

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

what is that Div2B :"/

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

    2^i + x (x < 2^i) > 2^j + y (y < 2^j) if i > j

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

      yes. that is precisely what i was trying to do.

      iterate left to right,

      get the maxm guy in q , find its pairup in p and check with ans[i]

      again iterate left to right,

      get the maxm guy in p , find its pairup in q and check with ans[i]

      got so many WAs on tc3.

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

        can't see the code yet so some guesses

        forgot the case when max p_i == max q_i

        overflow

        compared the modules instead of the actual values like the guy below said

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

          idts i am overflowing any way.

          here is my code,

          v => stores power of 2 precomputed.

            int maxi = -1,mx_idx=-1;
              for(int i=0;i<n;i++){
                  if(q[i]>maxi){
                      maxi = q[i];
                      mx_idx = i;
                  }
                  ans[i] = max(ans[i],(v[q[mx_idx]]%mod+v[p[i-mx_idx]]%mod)%mod);
              }
              
              maxi = -1,mx_idx=-1;
              for(int i=0;i<n;i++){
                  if(p[i]>maxi){
                      maxi = p[i];
                      mx_idx = i;
                  }
                  ans[i] = max(ans[i],(v[p[mx_idx]]%mod+v[q[i-mx_idx]]%mod)%mod);
              }
          
              for(int i=0;i<n;i++) cout<<ans[i]%mod<<" "; cout<<endl;
          

          could u find a reason?

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

        While finding the maximum, you are taking modulus. So, when taking modulus the maximum value is becoming lesser than second maximum value. So, instead of calculating the maximum first, we have to compare the values of p[i] & q[i], and then we have to find the answer.

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

          could u explain with a testcase ? i am still not able to understand why.

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

          oh HolyFUCK. I got you both. FUCK FUCK!

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

            bro please tell me also i too got wa on pretest3 3 times!

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

              So here's what was going wrong in my code:

              I was comparing pairs based on the expression (2^p % mod + 2^q % mod) % mod directly while iterating.

              The issue is that when p and q are large, 2^p % mod and 2^q % mod can overflow and wrap around, giving smaller values than they actually represent.

              Because of that, a pair like (60, 55) might appear smaller than (30, 29) just because modular arithmetic distorts the comparison—even though 60 > 30 and 55 > 29.

              So what I should've done is:

              First compare the raw exponent values (p, q)—without applying modulo—to decide which pair is lexicographically larger.

              Only after picking the better pair, apply the modulo while computing the final value: (2^p + 2^q) % mod.

              That way, I'm doing all comparisons on the actual exponent values and only reducing the result modulo mod once at the very end, avoiding any distortion from early modulo.

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

                got it thank you!

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

                Should have done this (I haven't done this in contest either )-

                You want to compare two expressions:

                2^x + 2^y vs 2^a + 2^b

                Instead of computing powers directly, you can exploit the properties of exponentials.

                If x > a, then 2^x > 2^a and dominates the sum

                If x < a, then 2^a > 2^x => done

                If x == a, then compare the second term, i.e., 2^y vs 2^b => again y > b => greater

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

Glad I couldnt figure out A immediately and decided not to participate further :)

»
4 weeks ago, hide # |
 
Vote: I like it -9 Vote: I do not like it

Could anyone kindly help explain why this solution isn't working(at test case 3) for problem B? TIA

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

long long power(long long base, long long exp, long long mod) {
    long long res = 1;
    base %= mod;
    while (exp > 0) {
        if (exp % 2 == 1) res = (res * base) % mod;
        base = (base * base) % mod;
        exp /= 2;
    }
    return res;
}

int main(){
    ll tt;
    cin>>tt;
    //tt=1;
    ll mod=998244353;
    while(tt--){
        ll n;
        cin>>n;
        ll p[n],q[n];
        for(ll i=0;i<n;i++){
            cin>>p[i];
        }
        for(ll i=0;i<n;i++){
            cin>>q[i];
        }
        ll up=0,down=0,upPos=0,downPos=0;
        pair<ll,ll>res[n];
        for(ll i=0;i<n;i++){
            if(p[i]>up){
                up=p[i];
                upPos=i;
            }
            if(q[i]>down){
                down=q[i];
                downPos=i;
            }
            if(up>down){
                res[i].first=up;
                res[i].second=q[i-upPos];
            }
            else if(up==down){
                res[i].first=up;
                res[i].second=max(q[i-upPos],p[i-downPos]);
            }
            else{
                res[i].first=p[i-downPos];
                res[i].second=down;
            }
        }
        for(ll i=0;i<n;i++){
            cout<<(ll)(power(2,res[i].first,mod)+power(2,res[i].second,mod))<<" ";
        }

        cout<<"\n";
    }

    return 0;
}
  • »
    »
    4 weeks ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    there might be other errors also

    but one i can see is in

    cout<<(ll)(power(2,res[i].first,mod)+power(2,res[i].second,mod))<<" ";
    

    you also need to take mod after doing sum. (Did the same mistake :(

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

    try adding another mod at the end after taking sum while printing

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

    You forget to % mod again when printing the answer.

    At this part of your code, for(ll i=0;i<n;i++){ cout<<(ll)(power(2,res[i].first,mod)+power(2,res[i].second,mod))<<" "; }

    Supposedly, for(ll i=0;i<n;i++){ cout<<(ll)(power(2,res[i].first,mod)+power(2,res[i].second,mod)) % mod <<" "; }

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

    // age dhore niben up = p[0] down = q[0] ll up = p[0], down = q[0], upPos = 0, downPos = 0;

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

div2C<<div2D

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

    yea C and D were wild

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

      Div2 A-C were fun though. But soon gave up on D. Still no idea now.= =

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

        for D I kept trying something around "loosely" gathering information about the values by going thorough the queries. In the sense that, every time u do something, u know something about the values from before. The information are all of the type "s[i] was at least v". And by keeping every min value, at the end, u can check if u get the correct thing. And that seemed to suffice in my head. It didn't work tho.

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

        my D ended up working. My solution was correct. I should've coded it myself instead of vibe-coding it...

        Fuck Gepetto

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

Submission

I think my solution to problem C is $$$O(n^3)$$$, why it can pass pretests?

UPD: Oh I got it, the time complexity is $$$O(n^2)\cdot \log{[\max(a_i)]}$$$.

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

you really telling me 5000*5000*log(5000) doesn't pass in div1A?? no comments

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

    You can precompute all GCD pairs up to $$$N - 1$$$ in $$$O(N^2)$$$ I think. You make a sieve like loop, where you iterate over numbers (results) $$$d$$$ and mark $$$GCD[i * d][j * d] = d$$$. The last time you substitute $$$GCD[i][j]$$$ will be for $$$d = gcd(i, j)$$$. You can avoid multiplication if you write it like this:

    vector<vector<int>> GCD(N, vector<int>(N, 1));
    for(int d = 2; d < N; ++d)
        for(int i = d; i < N; i += d)
            for(int j = d; j < N; j += d)
                GC[i][j] = d;
    

    Why is this $$$O(N^2)$$$? Because the number of substitutions is equal to $$$\sum (N / d)^2 < N^2 \zeta(2) = N^2 \pi^2 / 6 \sim 1.5 N^2$$$.

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

      Nice sieve, I believe you, but what is this symbol? where can I read more about this?

      ζ(2)

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

        It is known as the zeta function

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

          Yes, the lies machine did say that too,

          heard of it few times, but never really fiddled with it.

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

            It's just summation of reciprocals of squares up to infinity, ie. $$$\sum 1/k^2$$$. It's just notation for this, a Riemann zeta function. It just so happen that while the sum of reciprocals (ie. $$$\sum 1/k$$$) diverge, this sum converges to this value $$$\pi^2/6$$$. Since we are adding up to $$$N-1$$$ and not to infinity, the sum in the time complexity is less than that and the whole thing is $$$O(N^2)$$$.

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

              good to know, I never used it before (at least in contests) in my time complexity appromixation.

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

      You could also do $$$GC[i][j] = GC[j\%i][i]$$$

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

    mine passes though?

    322233494

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

      I forgot you can't see code few minutes after contest, so here.

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

    bfs (towards 1 / global gcd) turns out to be much faster
    (although I can't figure out the exact complexity in my head right now, can someone figure?)

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

Div2A>Div2B

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

Why so hard?

»
4 weeks ago, hide # |
Rev. 2  
Vote: I like it -6 Vote: I do not like it
Images

Find the difference

First TLE and second AC

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

Thanks for the nice contest!

Really, I was quite surprised by both the simplicity and difficulty of div1B/div2D. It's really easy to fall down the rabbit-hole of erroneous thought. I was only able to do it after using the technique "ok, instead of thinking in a straightforward manner, let's think in reverse (ie, bottom-up)". Once you start thinking that way, the problem becomes very straightforward and you realize that the solution is like 10 lines of code.

I wonder why I struggled so much with it... I guess for future reference, be more prepared to think in reverse?

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

    geez, I did thoughta about thinking in reverse immediately, but the solution is still not straightforward to me. So sad.

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

      If you want, I can give you the following hint:

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

        Kinda get it. Still it is quite intricate. Thx!

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

          I mean, the description is kinda scary, but really, the solution just ends up being:

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

    How is the solution straightforward when thinking in reverse?

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

Good problems but I took way too long to solve them :( Skill issue at work again.

How to solve $$$D$$$?

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

Can anyone tell me what is the pretest 9 of problem div2 C??

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

Why is time limit on 1A and 1C so tight? I was just optimising constant factor for most of the time on C, not fun at all. If O(n * m * H) is not supposed to pass set higher limits on them. If it is supposed to pass set lower limits.

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

Please Help How to Solve B?

I got wrong answer in tc3, got pounded by B today.

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

    Yeah me too. I handed in like 7 times and they all got WA in pretest 3. No idea about the edge case.

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

    While finding the maximum, you are taking modulus. So, when taking modulus the maximum value is becoming lesser than second maximum value. So, instead of calculating the maximum first, we have to compare the values of p[i] & q[i], and then we have to find the answer.

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

It was nonsense To prove my point, only 300 people were able to solve more than 3 questions

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

can someone please point out why this code failed on pretest 3 submission. thank you

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

How do you solve Div2C?

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

    Make all elements in the array equal to the gcd of the array. Use dp to find the minimum number of operations to make a single element the gcd of the entire array, then apply n-1 operations.

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

      How can I use DP here?

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

        dp[cur] = number of operations required to make it the gcd of the entire array. For each element in the array such that gcd(cur, a[i]) < cur, dp[cur] = min(dp[cur], dp[gcd(cur, a[i])+1]. Base case is dp[gcd of entire array] = 0.

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

          Bro can you recommend some problems or resources similar to learn this kind of DP.I have seen only knapsack and some popular patterns

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

            it was basically a knapsack kind of dp only.. just maintain an index and previously accumulated gcd , decide whether to pick it up or not and update the gcd accordingly..

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

            I originally wrote a knapsack-like solution, where you could either make cur = gcd(cur, v[i]), or just continue to pos+1. This is similar to the knapsack take/not take idea. This resulted in TLE due to the tight bounds though, so I just realized that the answer for some particular cur value is independent of position for this problem. Thus I reduced the dimension of the DP and passed.

            int dfs(int pos, int cur, int target, vector<int>& v) {
                if(pos>=v.size()) {
                    if(cur==target) return 0;
                    else return 1e9;
                }
                if(dp[pos][cur] != -1) return dp[pos][cur];
                return dp[pos][cur] = min(dfs(pos+1, cur, target, v), dfs(pos+1, __gcd(cur, v[pos]), target, v)+1);
            }
            
      • »
        »
        »
        »
        4 weeks ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        dp on subsets ,selecting a minimal subset whose gcd is equal to gcd of whole array

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

      let call the gcd of array is g

      my idea is if the there is an element equal to g, then I will output n — [number of element equal to g]. if there are no such element, then it take maximum 2 operations to produce g, so I perform brutal force to find whether there is any couple of elements that produce g. If it does have one then output n, else output n + 1 instead.

      However, my approach got wrong at pretest 9, and I can’t find a counter-testcase against my logic.

      this is my submission 322294608

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

why frozen?

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

First time getting stuck on Problem B for so long. (why so hard contest)

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

Bro ,i understand your urge to provide great problems to us and honestly they were good as they were not constructive (upto C) as per me ,but i think B and C are hard as per their numbers.I don't know how so many people were able to solve C that too using BFS.This was definitely great contest to learn,but C was too hard and not trivial.

Anyways please recommend me some more problems like C ,i want to get over these type of problems.

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

Quite frustrating that linear complexity for 2B in Python was not enough :/

After 1 hour of bumping my head at it I cached the exponents of 2 as a global variable and got it passing on pretests.. Let's see what the final tests do.

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

I think I had the biggest comeback in codeforces history today Solved question B in 1:50:18 Solved question C in 1:59:52 322287747 322294715

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

Got the idea for B correctly but for some reason pretests failed. Interesting problem. At one point I forgot they were permutations and considered 2 maximums.

Basically find the largest number and its index in P then 2^that number + corresponding in Q. The same with Q.

It'd be nice if C++ had modular exponention.

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

    I used the similar approach but it failed on pretest 3, waiting for the test case :(

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

    If you have two positive integers $$$P$$$ and $$$Q$$$, both $$$\leq 10^5$$$, you can proceed in the following way.

    Let's compute an array of all powers of $$$2$$$ modulo $$$MOD = 998244353$$$. You can do this with this piece of code:

    vector<ll> powers(N+5);
    powers[0] = 1;
    for(ll i = 1; i <= N; i++) powers[i] = (powers[i-1] * 2) % MOD;
    

    Now powers[i] stores $$$i$$$-th power of $$$2\,(mod\,998244353)$$$. You can now compute $$$2^P+2^Q\,(mod\, 998244353)$$$ as follows:

    (powers[P] + powers[Q]) % MOD
    
»
4 weeks ago, hide # |
 
Vote: I like it +28 Vote: I do not like it

Div1C has a bit of the old Codeforces vibe.

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

In 1A's DP. If I check if the dp[j]!=INF before updating dp[gcd(i, j)] I can got AC, but TLE on #7 if I didn't check it. And, my solution is $$$O(5000^2)$$$ by getting all 5000*5000 gcds before calculate the test cases. I can't understand why the time limit is unmeaningful tight.

Good Luck & Have Fun! [Fire][Fire][Fire]

Sorry, I never have a good luck and I can't have fun in this round, only the fire fit my emotion.

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

    I also had the concern about the constant factor of $$$5000^2$$$ GCD's, but luckily my solution passed, so I checked the difference between my solution and your first submission.

    It turned out:

    • If you implement GCD with recursion, it will timeout. Using std::gcd is OK.

    • During the DP, you should update dp[gcd__[a[i]][j]], not dp[gcd__[j][a[i]]]. It's due to the cache efficiency. gcd__[a[i]][j] is a contiguous memory access but gcd__[j][a[i]] is not.

    With the two fixes (and without DP[i][j]!=INF pruning) you can get AC (322321188). I first thought it's all about the speed of GCD but the second fix was also necessary to pass the test 7.

    I agree that the time limit is a bit tight. However, given that just updating dp[gcd(a[i],j)] was enough to get AC, it's understandable that author didn't see the necessity to increase the time limit.

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

      As I recently found out (and probably many people did but considered unimportant), there is a very easy way to $$$\gcd(i,j)$$$ for all $$$1 \le i,j \le n$$$ in $$$\mathcal{O}(n^2)$$$ time. The proof is a little mathematical though.

      Let $$$k$$$ be a candidate of $$$\gcd(i,j)$$$. Then, both $$$i$$$ and $$$j$$$ must be a multiple of $$$k$$$. Among all values that swept through $$$(i,j)$$$, the largest such value of $$$k$$$ must be the value of $$$\gcd(i,j)$$$. So perform a doubly nested loop inside the loop for $$$k=1\dots n$$$, analogously to any sieve-like algorithm that relies on the Harmonic Lemma.

      The time complexity. Let $$$\displaystyle f(n)=\sum_{k=1}^\infty {\frac{n^2}{k^2}}$$$. This becomes $$$\displaystyle n^2 \sum_{k=1}^\infty {\frac{1}{k^2}}$$$. The factor in the sum is known to converge, and due to the Riemann Zeta function we know that its value is $$$\zeta(2) = \pi ^2 / 6 \approx 1.65$$$. So our number of operations is bounded above by $$$1.65n^2$$$, meaning that we have an algorithm to preprocess all $$$\gcd$$$ in good time complexity and also great constants.

      The relevant submission, 322328173, passes in 234ms.

      EDIT: I just got notified that you can just simulate the Euclidean algorithm in DP to get $$$\mathcal{O}(n^2)$$$. That is true. Not having to rely on $$$\gcd(i,j)=\gcd(i,j-i)$$$ and still getting great constants is pretty cool though.

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

        Hi, im a bit confused, why do we need to precompute gcd when the gcd computation of c++ compilers are pretty optimized?

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

          std::gcd still has $$$\mathcal{O}(\log \max(a,b))$$$ time complexity. If you precompute, it will be $$$\mathcal{O}(1)$$$ afterwards.

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

I used BFS in problem C but got wrong answer, was I thinking correct? I inserted initial array elements in the queue, with their turns marked as 0, then for every element polled from queue , lets call it c, I calculated its gcd with all the array element, and if the calculated gcd , call it x , is not in the queue I insert it with its turn been equal to turn[x]=turn[c]+1. Here turn represent number of operations needed to get down to x. Suppose g is the gcd of the whole array , then my answer is n-1+turns[g]. In special case when turn[g]==0, I will calculate count of g in array and answer would be n-count[g]. Let me know what I missed.

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

https://codeforces.com/contest/2115/submission/322293995

why does this TLE for Div1C? I'm pretty sure it's O(n*m*h), which should be comfortably AC.

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

322294608

can anyone tell me why my code was wrong at pretest 9 (div2C)

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

    I'm not allowed to see your code but I'm think you might be wrong on this test =)

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

      My solution gives 6 for this, but still failed :(. Check my comment above,I am lost

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

      Oh, thanks, I assumed that the maximum operation to produce the number that equal to gcd of array is 2. how dumb am i....

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

Amazing contest! But the time limit for Div2D and Div2C was very tight. My Div2C got TLE for 5000*5000. My O(nlogn) solution for D also got TLE cause I used too many maps. My mistake for not writing in an optimized way, still not having such a tight bound would have been great.

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

I got no idea to solve problem D :( ,is there some simple idea to tackle it ?

Also struggled a bit in understanding what is happening in A , but logic was not so difficult finally

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

Nice Chinese TLs, guys.

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

    to be honest, $$$100\times 400\times 4000$$$ in C seemed kind of wild

    and it turns out to be way quicker than i thought it would be...

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

      Also the ML didn't allow this complexity to pass. Too narrow.

  • »
    »
    4 weeks ago, hide # ^ |
     
    Vote: I like it -18 Vote: I do not like it

    I'm sorry, but there is a fairly simple $$$O(m ^ 2 h)$$$ solution for Div1.C, and we have no other choice.

    • »
      »
      »
      4 weeks ago, hide # ^ |
       
      Vote: I like it -41 Vote: I do not like it

      It was a very good round with pretty tought problems and a lot to learn from. You'll did nice jobs making problems and conducting the contest.

»
4 weeks ago, hide # |
 
Vote: I like it -40 Vote: I do not like it

Very good round! D was super nice.

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

Div. 2 A Simple solution

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

The Div2C should have allowed n^2*log(5000) to pass

»
4 weeks ago, hide # |
Rev. 2  
Vote: I like it -18 Vote: I do not like it

const ll MOD =998244353; long long binpow1(long long a, long long b, long long m) { a %= m; long long res = 1; while (b > 0) { if (b & 1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } vector<ll> pow2(200005); void chill() { int n; cin>>n; vi p(n); take(p,n); vi q(n); take(q,n); vector<ll> r(n, 0); vi pp(n,0); vi qq(n,0); r[0] = (pow2[p[0]] + pow2[q[0]]) % MOD; for (int i=1;i<n;i++) { if(pow2[p[i]] > pow2[p[pp[i - 1]]]){ pp[i] = i; } else{ pp[i] = pp[i - 1]; } if (pow2[q[i]] > pow2[q[qq[i - 1]]]){ qq[i] = i; } else{ qq[i] = qq[i - 1]; } int ind1 = pp[i]; int ind2 = qq[i]; r[i] = max(r[i],(pow2[p[ind1]] + pow2[q[i - ind1]]) % MOD); r[i] = max(r[i],(pow2[p[i - ind2]] + pow2[q[ind2]]) % MOD); } for (auto &it : r){ cout << it << " "; } nl; } int main() { in_trice int times = 1; cin >> times; // cout<<times<<endl; for (int i = 0; i < 200005; ++i) { pow2[i] = binpow1(2, i, MOD); } for(int i=1;i<=times;i++){ chill(); } return 0; }

Can someone please tell me why this failed on testcase - 3 PROBLEM B

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

    You're essentially trying to compare two numbers here, obtained after % MOD. You should be comparing the powers of two.

            r[i] = max(r[i],(pow2[p[ind1]] + pow2[q[i &mdash; ind1]]) % MOD);
            r[i] = max(r[i],(pow2[p[i &mdash; ind2]] + pow2[q[ind2]]) % MOD);
    
  • »
    »
    4 weeks ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    The problem asks you to find the (max value) MOD 998244353 not the MAX (value MOD 998244353)

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

    if(pow2[p[i]] > pow2[p[pp[i — 1]]]){ pp[i] = i; }

    I foresee some potential problem here. Do not compare pow2 with pow2 because modulus operation are taking in place there. I suggest to compare it directly.

»
4 weeks ago, hide # |
Rev. 3  
Vote: I like it +53 Vote: I do not like it

I must have some crazy bug in B. I took away the check that it is possible to attain the answer with the min operation (so basically the check that at least a or b equals c where c = min(a, b)), and my solution somehow turned from WA to AC. What's interesting is my AC solution is very obviously wrong, since it doesn't output -1 on any tests like:

1

6 4

1 1 1 1 2 3

1 2 5

1 2 6

3 4 1

3 4 2

What is more interesting, my AC and WA solutions should differ only on tests of this type, and my AC solution somehow passes while being wrong on them, while my WA solution doesn't while being correct on them... Would be very thankful if someone could explain to me wtf is going on

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

Are pretests for 1B too weak? My wrong attempt passed during the contest, but i realized it and fixed it afterwards.

Hope system tests get all wrong solutions WA.

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

    Also I was stucked in 1C for precision problems, since large combination numbers are needed.

    Don't know whether official solution requires it or not.

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

      No need for large numbers.

      Let’s denote $$$H = max(a_i)$$$. While there are at least two different numbers in the array, the optimal thing is to act greedily: reduce the maximum number if the sword doesn’t shine, and reduce all numbers otherwise (unless the minimum is already 1). If we fix the number of steps it will take for the “greedy part” to be over (i.e. all numbers are equal), it’s easy to calculate the probability of this happening: a dp where your state is $$$(a,b) =$$$ there are $$$a$$$ operations left in the greedy part (at most $$$m$$$), and we still need to apply $$$b$$$ non-shine operations ($$$b$$$ is initially equal to $$$\sum_{i=1}^{n}(a_i - \min(a_i))$$$, so at most $$$n*H$$$). Transitions are straightforward and this dp is $$$\mathcal{O}(m \cdot n \cdot H)$$$.

      Once all the numbers are equal, you can notice that you if you use the “non-shine” operation once in a number, you need to do it in all the others too (otherwise they will never be equal again). You can do a second dp where state is $$$(a,b,c) =$$$ there are $$$a$$$ operations left (at most $$$m$$$), we already used $$$b$$$ “shine” operations (at most $$$H$$$), and there are $$$c$$$ elements in the array (at most $$$n-1$$$) in which we reduced their value by one (if we reduce all the $$$n$$$ values by one, we increase $$$b$$$ by one and set $$$c$$$ to zero). Transitions are not too complicated neither.

      When fixing the number of operations in the first part, the initial state for the second part is fully determined. Both parts have the same complexity, so full solution is $$$\mathcal{O}(m \cdot n \cdot H)$$$, and there are no big numbers involved.

»
4 weeks ago, hide # |
 
Vote: I like it -29 Vote: I do not like it

Very hard problems... The problems are way too hard to solve within the time in contest.

I don't think it's a good contest

»
4 weeks ago, hide # |
Rev. 2  
Vote: I like it -25 Vote: I do not like it

whatt

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

Petition to set all round duration to 3h

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

too hard /_ \

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

How to solve Div2-B ?

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

    first , you need to notice that taking the greatest exponent will always result in a better answer, because it will be greater than the other ones by at least a factor of 2, so you will be tracking the prefix max on p and q . now for every index i , one exponent would be the biggest value in the prefixes of both p and q, now to get the other exponent you need some caseworking , basically if the biggest value was on the p side you need to get the index it was in (you can create the index arrays for both p and q ) and the other exponent will automatically be the q[i-(that index)], vice versa if the max was in q , now if the prefix maxes were equal in both p and q , you'll need to consider 2 cases , take the index of the max in p , take the index of the max in q , than the ans would be the max between p[i-(second index)] and q[i-(first index)] . and do that for all i to construct the answer

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

Div2 C's Time Limits are too tight,I don't think i like this problem

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

Someone who solved 2C using bfs,please explain me your approach and have you solved this kind of problem before and if yes and possible ,please link it.

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

Was there a faster solution for D1A? I ended up changing my code in fear of system tests (1.5s runtime / 2s) and it was still incredibly slow.

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

    my complexity was n * maximum * gcd computation ... it ran for 1.5s in pretests ... but it passed system test just now

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

    My solution is $$$O(N^2log(K) / log log(K))$$$ (where $$$K$$$ is $$$max \; A_i$$$) and it passes in 187ms: 322286852

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

anyone who was struck in 3rd testcase div2D, and then corrected the solution?

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

    yeah so for div2D my issue was with the backwards-walk logic. I had to split the cases more ((a, b) -> c, (a, b) -> b, (a, a) -> b, (a, a) -> a). And just a whole bunch of ifs regarding the lower-bounds and exact values

    the core idea is just propagating lower bounds for the values and then doing a recheck at the end

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

Getting TLE related to this: https://codeforces.com/blog/entry/97390

Why was i not able to correct my code during the contest? Other competitors got tle on test case 5 during contest and were able to make changes to get AC.

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

    happened to me as well, i changed long long to int and it ran in about 1200ms, my code had the complexity of 5000*n*log(5000) approximately

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

D2C had 15 pretests...mine was WA on 14 (╥﹏╥)

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

Couldn't figure out how to speed up B, any hint?


pot2 = [pow(2, x, 998244353) for x in range(100001)] for _ in range(int(input())): n = int(input()) P = list(map(int, input().split())) Q = list(map(int, input().split())) potP = [pot2[p] for p in P] potQ = [pot2[q] for q in Q] r = [] for i in range(n): mv = 0 for j in range(i+1): v = (potP[j] + potQ[i-j]) % 998244353 if v > mv: mv = v r.append(mv) print(*r)
»
4 weeks ago, hide # |
 
Vote: I like it +10 Vote: I do not like it

My teacher once told me, "If the contest is organized by Chinese, don't participate. All their problems will be math-related." Today, I participated in the contest and became convinced that my teacher was right.

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

Why wouldn't you bound $$$m$$$ to $$$4000$$$ in D1C? Why does $$$100 \times 400 \times 4000$$$ pass? Why doesn't my solution pass then?

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

My solution for Div2C was a brute force, I want to make all the elements equal to the GCD of the array

I will try each time to get the minimum gcd until the minimum element in the array is equal to this gcd, finally count the number of elements that aren't equal to this gcd

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

    precalculating the gcd for all possible combinations using a sieve will probably make it more efficient.

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

minute of silence for those whom got TLE with $$$O(n^2 \log n)$$$ in C

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

    You could have reduced it to n2 by storing gcd of all numbers from 1 to 5000 with each other in a vector of vector. I did that and my code got accepted.

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

Problem 2 was difficult!

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

Why was my first submission skipped?

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

    If you submit on a problem which got accepted, only the last submission counts, also you get -50 for resubmit and I think the score you get is less too. All previous submissions get skipped

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

Why frozen? I cant submit my code.

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

thanks for the div2 C loved raging and almost wanting to end everything

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

Can anyone explain why my latest submission of C is counted, even though my previous submission is also AC. It should be other way around right?

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

Goofy ahh contest

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

Why is the standing still frozen?

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

That was a very tough contest, I never performed this badly. I think I will see a -100 delta. But anyway, thanks for the contest and the efforts to prepare those problems.

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

DIV2C/DIV1A should be re-evaluated with an adjusted time limit.

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

can anyone explain why for div2b this fails... x = (pow2[ma] + pow2[b[i — idA]]) % mod; y = (pow2[mb] + pow2[a[i — idB]]) % mod; cout << max(x, y) << " ";

note: ma is maximum prefix of vector a idA is the index of maxim prefix and the b names are just the reverse..the codes which have gotten ac they have compared these two only but with different if()else conditions then why is this code wrong

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

    if maxa and maxb is equal, then you should compare the second terms b[i — idA] and a[i — idB]. But you are first summing up the powers of 2 first(which are modulo X) and then compare with gives the wrong answer, I did the same as well at first,

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

Can anyone provide a hint for C?

It seems like it has no pattern whatsoever.

  • »
    »
    4 weeks ago, hide # ^ |
     
    Vote: I like it +15 Vote: I do not like it
    Hint 1
    Hint 2
    Hint 3
»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

How the same code for Div2 C sometimes getting accepted and sometimes giving TLE on TestCase 7??

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

    Can you please help the code i have submitted for div2b is same as ypur first submission why did it fail why it isnt simply max(ab,cd) as in your code

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

      Sure, Let's suppose the value of ab is greater than cd.

      Now when you are taking mod, then the value of ab might become smaller than cd, but in reality value of ab is greater than cd. Consider this example

      int ab = (binpow(2,44) + binpow(2,4))%mod; int bc = (binpow(2,30) + binpow(2,30))%mod;

      Here, binpow(2,x) means (2^x)%mod.

      After this step, the value of ab & bc are as follow: ab 125811513 bc 150994942

      Now, here you can see that in reality ab is greater than bc, but due to taking mod, it's value has become less. So, instead of calculating their values, we should just compare the powers of 2, which I have done in my next submission. I hope this helps.

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

i used bellman-ford DP to solve div2c

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

not really sure what learning did Div2 C really had, with tough time constraints, i mean like same dp solution which passes with int16, is meant to TLE on TC 7 if u use long long by default in ur template, seriously??

Long long solution fails: https://codeforces.com/contest/2116/submission/322307127

int16 solution (above solution when done with int16) passes: https://codeforces.com/contest/2116/submission/322308744

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

    I also use int as long long, and I'm facing something weird, sometimes my solution is getting accepted, and sometimes it's giving TLE on TC-7.

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

those who wa on test 3 because of mod in div2b

»
4 weeks ago, hide # |
 
Vote: I like it -10 Vote: I do not like it

https://codeforces.com/contest/2116/submission/322315881 In Div2C why is it giving tle on using long long and got accepted when used int..

  • »
    »
    4 weeks ago, hide # ^ |
    Rev. 3  
    Vote: I like it -8 Vote: I do not like it

    Well, your solution has a really huge constant factor due to using a deep recursion (2.5e7) and self-written recursive gcd function. It is known that using long long type increases time of arithmetic operations(including computing a reminder, which is necessary for gcd). It is very likely that this is why you get TLE. Rewrite you dp in iterative way, use std::gcd (which is written not recursively, but iteratively -> faster) and you will get AC with both long long and int. Here you can also invent some funny optimizations, like pre-compute all gcds for all pairs of numbers <= 5000. but they are 100% redundant.

    UPD: it seems like I wasn't correct at all, probably the only way to pass a solution is to precompute these gcds. The takeaway is : you should use #define int long long carefully when dealing with problems with tough TL or ML.

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

Why is there no rating change dor div 1

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

My solution for 2C passes with int (1.5s) but TLEs with long long :*)

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

    long long is slower than int, in most cases it shouldn't matter but for tight time limits like C, it can cause TLE.

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

Goodluck to all. someday i hope to participate in div 2

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

I realize I should learn to skip challenging problems earlier in future contests. During the competition, I spent 1 hour and 20 minutes struggling with Problem C. However, when I reviewed Problem E after the contest ended, I managed to solve it in just one hour! This experience has taught me the importance of adjusting my time allocation strategy during coding competitions.

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

Is there any glitch in system testing? My submission for div2 C was accepted during contest, failed on test 7 in system testing. Now when I submit the exact same code, it is getting accepted. Was hoping for a positive delta but missed because of this :)

Gellyfish any explanation — or anything that can be done about it? A rejudge would be appreciated

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

    Same, went from +100 delta to -50 because of this. Easily solved C in contest and if I got TLE during contest could have optimized the code during the 1.5hrs I was working on problem D.

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

      I guess using a std::set to store all the ''useful'' dp states will make your code ' complexity far below 5000*5000

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

      Yes, if our code has failed, so should be others' having same logic and code as ours. People having same code as me have got AC which is really unfair.

      +100 to -50!? This shit hurts

      Hope things turn around for you soon.

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

I think Div1-C has weak test cases. Many submitted codes can be hacked (time limit) with the following case:

t=100
1 4000 50
400
(repeated 100 times)
»
4 weeks ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Why am I getting "unexpected error" when I attempt to submit for 2116A - Gellyfish and Tricolor Pansy and 2116B - Gellyfish and Baby's Breath?

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

    maybe its wrong with the server or ...

    try with another device or wait or refresh ur web<3

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

my code gets AC on div2-D,but i think it is fake;how to hack it?https://codeforces.com/contest/2116/submission/322329033

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

Hey Gellyfish can we get a rejudge? I got A/C in contest for C on my first submission, and now got rejudged to TLE. You've got people who have 5+ failed submissions that later got A/C, this is unfair to the contestants that got a false A/C during the contest with no chance to correct this error. My ranking went from Top 500 to ~4,000 for a silly judging error

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

    Is it possible that this is because although the theoretical time complexity of your code meets the problem's requirements, the constant factor is too large? It's normal for the judging system to have some fluctuations.

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

      Yeah, in my case i used std::set for dp states, which barely passes (or fails) vs std::unordered_set with my exact same code passes with time to spare.

      It's just BS that people who got 5+ failed submissions rocketed past me in the standings and i had no chance to correct my code. I solved the problem relatively easily in around 10 minutes understanding the time complexity and got accepted on first submission.

      My projected rating post contest was supposed to be 1750, instead i ended up back at specialist. Spent 1:30 mins on problem D, if i had known there was any chance of code failing on C i could have easily corrected it within this time. Trash judging IMO

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

can anyone tell me where to find editorial of this contest

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

Becoming one of the winners of Div.2 for the first time and become a Candidate Master!

The question is very interesting, but I didn't finish 2F in the end.

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

May I inquire if there are any official tutorials, and when they will be released?

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

Normally, Codeforces updates ratings and releases tutorials 2-3 hours after the system test. Why is this round so slow? Are there any issues with Codeforces?

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

First reach CM!

»
4 weeks ago, hide # |
Rev. 2  
Vote: I like it -31 Vote: I do not like it

.

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

Hey, Can anyone look into mycode for Problem B Div2, It is failing for test 3.Not sure why it is failing and able to figure where went wrong.Help me on this.

Your code here...

# Online Python compiler (interpreter) to run Python online.
# Write Python 3 code in this online editor and run it.
mod = 998244353
for k in range(int(input())):
     n = int(input())
     a = list(map(int, input().split()))
     b = list(map(int, input().split()))
     r = []
     ma1 = [-1,-1]
     ma2 = [-1,-1]
     for i in range(n):
        if a[i]>ma1[0]:
             ma1[0] = a[i]
             ma1[1] = i
        if b[i]>ma2[0]:
             ma2[0] = b[i]
             ma2[1] = i
        r.append(max(pow(2,ma1[0],mod)+pow(2,b[i-ma1[1]],mod),
                 pow(2,ma2[0],mod)+pow(2,a[i-ma2[1]],mod)))
        r[i] = r[i]%mod
     print(*r)
         
     
»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
ll binpow(ll a,ll b){
    ll ans=1;
    while(b>0){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b>>=1;
    }
    return ans%mod;
}

void solve(){
    ll n; cin>>n;
    vector<ll>a(n,-1),b(n,-1);
    for(auto &x:a){
        cin>>x;
    }    
    for(auto &x:b){
        cin>>x;
    }
    set<pair<ll,ll>>st1,st2;
    vector<ll>ans;
    for(ll i=0;i<n;i++){
        st1.insert({a[i],i});
        st2.insert({b[i],i});
        ll topbestidx=st1.rbegin()->second;
        ll belowbestidx=st2.rbegin()->second;
        ll maxi1=(binpow(2,a[topbestidx])+binpow(2,b[(i-topbestidx+n)%n]))%mod;
        ll maxi2=(binpow(2,a[(i-belowbestidx+n)%n])+binpow(2,b[belowbestidx]))%mod;
        ans.push_back(max(maxi1,maxi2));
    }
    for(auto &x:ans){
        cout<<x<<" ";
    }
    cout<<na;
}

where am i going wrong in qn B?

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

Can someone help me understand how the first solution is getting TLE. And, Even if it is getting TLE than how just that small change make the second solution pass

322340728

322341080

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

thanks for fast edtior

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

Oh I only solved 1 problem in Div.1. It's too hard T_T

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

I couldn't come with a DP solution for the Div2C, so I choose greedy method and it worked for me. When the GCD is not present in the array, I greedily keep on choosing the pairs which will give the least GCD, so first I scanned through all the pairs and then checked the pair with smallest no to every other no in the array. https://codeforces.com/contest/2116/submission/322288935

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

Please post editorial fast

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

when editorial

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

I am getting WA on TC-3. Please point out where i m going wrong..

322358648

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

why so many downvotes ? that was an interesting contest. thank you for the round

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

unpopular opinion: I've enjoyed the contest.

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

DIV 2, PROBLEM C, PRETEST 9

Input: 50 numbers... My Answer: 50 Given Answer: 53

My approach: I found the GCD of all the 50 numbers, which is 1. So there necessarily exists a co-prime pair in the 50 elements.

So, my first operation will be on this co-prime pair, which will give me 1. Now, for the remaining 49 elements, i will pair them with 1, one by one, and hence obtain all the ones.

In this way my total operations will be 50.

Please tell me where i went wrong?

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

Since there's no editorial yet, F has super low number of solutions even now but it seems

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

Although D1C was really hard for me, still it's quite nice to finally reach gm

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

Where is the solution of 2C?

  • »
    »
    4 weeks ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it
    #include <bits/stdc++.h>
    using namespace std;
    
    const int N = 5001;
    const int INF = 1e5;
    int g[N][N];
    
    void solve()
    {
        int n, cur_gcd = 0, cnt = 0, maxi = 0;
        cin >> n;
        vector<int> a(n);
        for (auto &v : a)
        {
            cin >> v;
            cur_gcd = g[cur_gcd][v];
            maxi = max(v, maxi);
        }
    
        for (auto &v : a)
            cnt += (v == cur_gcd);
    
        if (cnt > 0)
        {
            cout << n - cnt << "\n";
            return;
        }
        vector<vector<int>> dp(maxi + 1, vector<int>(n + 1, -1));
        for (int i = 1; i <= maxi; i++)
            dp[i][n] = INF;
        dp[cur_gcd][n] = 0;
        for (int j = n - 1; j >= 0; j--)
            for (int i = 1; i <= maxi; i++)
                dp[i][j] = min(dp[i][j + 1], 1 + dp[g[i][a[j]]][j + 1]);
    
        int ans = INF;
        for (int i = 0; i < n; i++)
            ans = min(ans, n - 1 + dp[a[i]][0]);
        cout << ans << "\n";
    }
    
    signed main()
    {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        cout.tie(nullptr);
    
        for (int i = 1; i < N; i++)
            g[i][0] = g[0][i] = g[i][i] = i;
    
        for (int i = 1; i < N; i++)
            for (int j = 1; j < i; j++)
                g[i][j] = g[j][i] = g[j][i % j];
    
        int T = 1;
        cin >> T;
        while (T--)
            solve();
    }
    
»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Is it too hard to post editorial for this contest?

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

Hi everyone Can anyone tell me where is my Folse in DiV2 Problem B pleas make loke in the code Thanks[submission:322445331]

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

Why so many downvotes? I think it's a great contest with themes.

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

Whether there is a communication group of learners, I have a lot of questions to know.

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

Hi, my submissions for this round has been skipped! this is the message I got

Your solution 322239991 for the problem 2116C significantly coincides with solutions Prady/322211648, Siddarth_MSR/322229699, mehul1512/322239991, Rafat_Kabir/322252055, AlterAB/322290280.

However, the coinciding code is already published on GeekForGeeks- link

pls upvote so I dont lose rating:(

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

Hi

My submission to the problem 2115C has been skipped due to similarity with some other submissions. However, that is because I had used a code snippet from GeeksForGeeks, published before the commencement of the round. Here is the link:

https://www.geeksforgeeks.org/minimum-length-of-subsequence-having-unit-gcd/

As it can be clearly seen, the article was published in 2023.

Please look into it Gellyfish errorgorn

Thanks!

»
4 weeks ago, hide # |
 
Vote: I like it -6 Vote: I do not like it

Below is a concise justification focusing on why nearly every correct 2116D solution follows the same template (hence the similarity is not plagiarism):


Why all correct solutions “coincide”

  1. 1. Segment‐tree for “last writer.”
  • We must know, for each final index i, which operation (or leaf) last wrote to i. The only efficient way (in O(log n)) is a segment tree that, at operation i (node u = n+i), does

    ``` childA = seg.get(xᵢ);

    childB = seg.get(yᵢ);

    left[u] = childA; right[u] = childB;

    seg.set(zᵢ, u);

    ```

    After all updates, owner[i] = seg.get(i). Every solver uses this same approach (or a DSU variant that amounts to the same).

  1. 2. Build the dependency tree.
  • Leaves 1…n represent original a-positions; internal nodes n+1…n+q represent the q “min” operations. For each u=n+i, we already recorded left[u] and right[u]. That gives exactly two‐child edges “u = min(left[u], right[u])”. No other structure captures “c[zᵢ] = min(c[xᵢ], c[yᵢ])” correctly.
  1. 3. Backward propagation of final values.
  • If node u is “top” (i.e. it produced some final b[j]), then min(value[left[u]], value[right[u]]) must equal b[j]. So both children need ≥ b[j]. Recursively push need[child] = max(need[child], b[j]) down to leaves. There is simply no alternative: you must reverse‐propagate all b’s to find minimal a[i].
  1. 4. Forward evaluation/verification.
  • Once each node u has need[u], iterate u=1…n+q in order:

    ```

    if (u ≤ n) value[u] = need[u];

    else value[u] = min(value[left[u]], value[right[u]]);

    if (u is top and value[u] != need[u]) fail;

    ```

  • If all top‐nodes match, output value[1..n]; otherwise “–1.” No one found a different way to confirm min(child1,child2) == need[u] other than computing it directly.

Because this four‐step method is essentially the only correct, O((n+q) log n) algorithm for “reverse c[z]=min(c[x],c[y]) to reach b,” everyone’s code ends up with the same segment-tree calls, the same left[]/right[] arrays, and the same backward/forward loops. The near-identical structure is simply the standard template—found in CP-Algorithms, GeeksforGeeks, and many CF editorials—not evidence of copying from another contestant.

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

My solution for problem 2116A was flagged for coincidence with UltraMate/322220362. I want to clarify that I wrote the code completely on my own during the contest and did not share it with anyone. I did not use any public code-sharing platforms like Ideone. The problem had a straightforward logic, and it’s possible that similar ideas led to similar implementations unintentionally. I kindly request the admins to review my case and consider that I had no intention to violate the rules. I will be more cautious in the future. Thank you for your understanding.

»
4 weeks ago, hide # |
 
Vote: I like it -10 Vote: I do not like it

Handle: ankitaSingh0036

I want to sincerely apologize for violating the contest rules regarding Problem 2116B. The solution I submitted (322272186) was not my own work. During a screen-sharing session, I saw code written by harshitjain without their knowledge or consent and submitted a similar solution as my own. They were completely unaware, and I take full responsibility.

This was a serious lapse in judgment. I understand the importance of fair competition and deeply regret my actions. I accept any consequences for this violation and assure you it will not happen again.

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

Handle: harshitjain

I received a notification regarding code similarity for Problem 2116B (submission ID: 322274436). I want to clarify that I wrote my solution independently in Visual Studio Code during the contest.

I was not aware that my screen was being viewed during a screen-sharing session, and I did not give anyone permission to use or copy my code. I did not collaborate with any other participant and was completely unaware that my solution had been accessed in this way.

The other user (ankitaSingh0036) has already admitted to copying the solution and accepted full responsibility. I respectfully request the Codeforces team to consider this explanation and their confession in your review, as I have not violated any contest rules.

Thank you for your time and understanding. here is the code that i wrote in vs code #include <bits/stdc++.h> using namespace std;

const long long MOD = 998244353;

long long power(long long x, long long y, long long mod) { long long res = 1; x %= mod; while (y > 0) { if (y % 2 == 1) res = (res * x) % mod; x = (x * x) % mod; y /= 2; } return res; }

long long getSum(long long x, long long y) { long long p1 = power(2, x, MOD); long long p2 = power(2, y, MOD); return (p1 + p2) % MOD; }

void solve() { int n; cin >> n; vector arr1(n); for(int i = 0 ; i < n ; i++) cin >> arr1[i]; vector arr2(n); for(int i = 0 ; i < n ; i++) cin >> arr2[i];

vector<int> res(n , 0);
int mx1 = -1 , mx2 = -1;
int idx1 = -1 , idx2 = -1;
for(int i = 0 ; i < n ; i++){
    if (arr1[i] > mx1){
        mx1 = arr1[i];
        idx1 = i;
    }
    if (arr2[i] > mx2){
        mx2 = arr2[i];
        idx2 = i;
    }

    int diff1 = i - idx1;
    int diff2 = i - idx2;
    int x1 = max(arr1[idx1] , arr2[diff1]);
    int x2 = min(arr1[idx1] , arr2[diff1]);

    int y1 = max(arr2[idx2] , arr1[diff2]);
    int y2 = min(arr2[idx2] , arr1[diff2]);

    if (x1 > y1){
        res[i] = getSum(x1 , x2);
    } else if (x1 < y1){
        res[i] = getSum(y2 , y1);
    } else {
        if (x2 > y2){
            res[i] = getSum(x1 , x2);
        } else {
            res[i] = getSum(y2 , y1);
        }
    }
}

for(int i = 0 ; i < n ; i++){
    cout << res[i] << ' ';
}cout << endl;

}

int main() { ios::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) solve(); return 0; } In my solution for Problem 2116B, I observed that for each position i, we need to compute a value based on some combination of elements from the two arrays. I realized that the result depends heavily on the larger elements encountered so far in both arrays.

To efficiently handle this, I kept track of the maximum elements seen so far in both arr1 and arr2, along with their indices (idx1, idx2). For each position i, I calculated:

diff1 = i — idx1 and diff2 = i — idx2 to reference a potentially better value from the other array at a certain offset.

Then, I took the maximum and minimum of these two values to form a meaningful pair.

The core insight I used was that:

The power of 2 grows exponentially, so the larger number in the pair will dominate the result.

That's why I focused on comparing the larger elements (x1, y1) from both strategies first.

Only if these were equal, I compared the smaller elements (x2, y2) as a tiebreaker.

Finally, I used a helper function getSum(x, y) to compute 2^x + 2^y % MOD, which ensures both correctness and efficiency under large constraints using modular exponentiation.

This logic allowed me to efficiently determine the best combination for each index and build the result accordingly.

Please look into it @Gellyfish @errorgorn

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

Hello,

My submissions for the round got skipped because of similarity with some other submissions on problem 2116C. Your solution 322229699 for the problem 2116C significantly coincides with solutions Prady/322211648, Siddarth_MSR/322229699, mehul1512/322239991, Rafat_Kabir/322252055, AlterAB/322290280.

However, that is because I had used a code snippet from GeeksForGeeks, which was published before the round started. This is the gfg link: https://www.geeksforgeeks.org/minimum-length-of-subsequence-having-unit-gcd/

Please look into it Gellyfish errorgorn

Thanks.

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

Handle: @harshitjain
Submission ID: 322274436
Contest: Codeforces Round 1028 div 2

I would like to respectfully clarify the reason for the similarity between my solution and that of @ankitaSingh0036 for Problem 2116B.

I wrote and submitted my solution independently using VS Code locally, and I did not upload or share my code on any public platform such as Ideone, Pastebin, or GitHub. However, during a screen-sharing session for unrelated reasons, another participant was able to view my code without my consent and submitted a similar solution. I was unaware that my screen was being monitored in a way that allowed this.

The user @ankitaSingh0036 has already acknowledged that they copied from me without permission. Their message states:

"I want to sincerely apologize for violating the contest rules regarding Problem 2116B. The solution I submitted (322272186) was not my own work. During a screen-sharing session, I saw code written by @harshitjain without their knowledge or consent and submitted a similar solution as my own. They were completely unaware, and I take full responsibility."

I understand the importance of Codeforces’ anti-plagiarism policy and acknowledge that unintentional leakage is also taken seriously. However, I had no intent to share my code or violate any rules.

I respectfully request that my submission be reconsidered, and my rating change be restored. Thank you for your time and fair evaluation.

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

Hi Handle: @harshitjain Submission ID: 322274436 Contest: Codeforces Round 1028

I wrote my solution independently using VS Code locally and did not share it publicly. During a screen-sharing session, another user (@ankitaSingh0036) viewed my code without my consent and submitted a similar solution. They have accepted full responsibility for this.

I had no intention to violate any rules and kindly request reconsideration of my submission.

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

    What's this ceremony of "screen-sharing session" DURING contest? Please enlighten.

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

      The screen-sharing session was for a separate college project and had nothing to do with the contest. I wasn’t aware my code was visible during the call. I never intended to share or leak it, and the other user has admitted to copying it without my consent. I hope you’ll consider this context while reviewing my case. Thank you.

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

        Apparently, your college has got serious multitaskers then. Doing college projects and participating in contest at the same time.

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

Dear Codeforces Team,

I recently received a message regarding a significant coincidence detected in my solution (Submission ID: 322252055) for Problem 2116C in Codeforces Round 1028 (Div. 2). The message indicated a potential rules violation due to similarity with other participants’ submissions. The message I received was:

"Your solution 322252055 for the problem 2116C significantly coincides with solutions Prady/322211648, Siddarth_MSR/322229699, mehul1512/322239991, Rafat_Kabir/322252055, AlterAB/322290280."

However, that is because I had used a code snippet from GeeksForGeeks, published more than 2 years before the commencement of the round. Here is the link: Minimum length of subsequence having unit GCD.

Clearly, according to the post regarding Third-party code by MikeMirzayanov,

Solutions and test generators can only use source code completely written by you, with the following two exceptions: 1.the code was written and **published/distributed before** the start of the round.

Please have a look into this Gellyfish errorgorn MikeMirzayanov.

Thanks!

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

why in test case 1 in C div1(Gellyfish and Eternal Violet) is said "Otherwise, if the sword does not shine in the first round, she will attack monster 1 in the first round. For the second round:" how about Gellyfish choose not to attack