Gellyfish's blog

By Gellyfish, 17 months 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 31.05.2025 17:35 (Московское время). 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

| Write comment?
»
17 months 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 😳

»
17 months 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

»
17 months 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 (葬送のフリーレン).

»
17 months 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.

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

This is my first contest as a specialist!

»
17 months ago, hide # |
← Rev. 3  
Vote: I like it -23 Vote: I do not like it

good luck

»
17 months 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.

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

Hoping that problems will be very easy

»
17 months 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

»
17 months 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'?

»
17 months 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

»
17 months 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.

»
17 months 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.(¬_¬)

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

Use no emojis in these blogs.

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

hope to solve 3 problems and get +delta

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

errorgorn is a interesting guy

a -> an

»
17 months 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

»
17 months 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.

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

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

»
17 months 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!

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

Happy Children's Day ;-)

»
17 months 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

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

all the best to everyone

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

Hope to not get wrong on first 3 submission

»
17 months 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 :)

»
17 months 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

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

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

  • »
    »
    17 months 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)

»
17 months 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)

»
17 months 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.

»
17 months 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!

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

    same same, i'm guessing the solution will be simpler than my dumb logic.

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

WA on pretest 9 in C?

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

what is that Div2B :"/

  • »
    »
    17 months 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

    • »
      »
      »
      17 months 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.

      • »
        »
        »
        »
        17 months 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

        • »
          »
          »
          »
          »
          17 months 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?

      • »
        »
        »
        »
        17 months 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.

        • »
          »
          »
          »
          »
          17 months 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.

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

          oh HolyFUCK. I got you both. FUCK FUCK!

          • »
            »
            »
            »
            »
            »
            17 months 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!

            • »
              »
              »
              »
              »
              »
              »
              17 months 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.

»
17 months 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 :)

»
17 months 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;
}
  • »
    »
    17 months 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 :(

  • »
    »
    17 months 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

  • »
    »
    17 months 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 <<" "; }

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

div2C<<div2D

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

    yea C and D were wild

    • »
      »
      »
      17 months 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.= =

      • »
        »
        »
        »
        17 months 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.

      • »
        »
        »
        »
        17 months 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

»
17 months 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)]}$$$.

»
17 months 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

  • »
    »
    17 months 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 \lt N^2 \zeta(2) = N^2 \pi^2 / 6 \sim 1.5 N^2$$$.

    • »
      »
      »
      17 months 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)

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

        It is known as the zeta function

        • »
          »
          »
          »
          »
          17 months 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.

          • »
            »
            »
            »
            »
            »
            17 months 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)$$$.

            • »
              »
              »
              »
              »
              »
              »
              17 months 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.

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

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

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

    mine passes though?

    322233494

    • »
      »
      »
      17 months 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
  • »
    »
    17 months 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?)

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

Div2A>Div2B

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

Why so hard?

»
17 months ago, hide # |
← Rev. 2  
Vote: I like it -6 Vote: I do not like it
Images

Find the difference

First TLE and second AC

»
17 months 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?

  • »
    »
    17 months 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.

    • »
      »
      »
      17 months 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
      • »
        »
        »
        »
        17 months ago, hide # ^ |
         
        Vote: I like it +5 Vote: I do not like it

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

        • »
          »
          »
          »
          »
          17 months 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
  • »
    »
    17 months ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    How is the solution straightforward when thinking in reverse?

»
17 months 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??

»
17 months 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.

»
17 months 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.

  • »
    »
    17 months 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.

  • »
    »
    17 months 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.

»
17 months 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

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

How do you solve Div2C?

  • »
    »
    17 months 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.

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

      How can I use DP here?

      • »
        »
        »
        »
        17 months 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.

        • »
          »
          »
          »
          »
          17 months 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

          • »
            »
            »
            »
            »
            »
            17 months 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..

          • »
            »
            »
            »
            »
            »
            17 months 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);
            }
            
      • »
        »
        »
        »
        17 months 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

    • »
      »
      »
      17 months 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

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

why frozen?

»
17 months 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)

»
17 months 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

»
17 months 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.

  • »
    »
    17 months 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
    
»
17 months ago, hide # |
 
Vote: I like it +28 Vote: I do not like it

Div1C has a bit of the old Codeforces vibe.

»
17 months 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.

  • »
    »
    17 months 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.

    • »
      »
      »
      17 months 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.

      • »
        »
        »
        »
        17 months 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?

        • »
          »
          »
          »
          »
          17 months 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.

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

https://codeforces.me/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.

  • »
    »
    17 months ago, hide # ^ |
    ← Rev. 2  
    Vote: I like it +8 Vote: I do not like it
    1. $$$\sum{n}\leq 100$$$, so $$$O(n*m*h)$$$ is already 1.6e8 iterations.
    2. Your array was in a bad ordering with respect to your loops. I transposed them and get an AC: 322329545
    3. Don't use long double when not needed.
    • »
      »
      »
      17 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      I think the biggest issue was using long double instead of double, but changing the loop order of the first loop also halves the time it takes to run, does anyone know why?

»
17 months 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)

  • »
    »
    17 months 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
    • »
      »
      »
      17 months 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

    • »
      »
      »
      17 months 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....

»
17 months 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.

»
17 months 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

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

Nice Chinese TLs, guys.

  • »
    »
    17 months 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...

  • »
    »
    17 months 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.

    • »
      »
      »
      17 months 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.

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

Very good round! D was super nice.

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

Div. 2 A Simple solution

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

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

»
17 months 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

  • »
    »
    17 months 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);
    
  • »
    »
    17 months 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)

  • »
    »
    17 months 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.

»
17 months 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

»
17 months 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.

  • »
    »
    17 months 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.

    • »
      »
      »
      17 months 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.

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

Petition to set all round duration to 3h

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

too hard /_ \

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

How to solve Div2-B ?

  • »
    »
    17 months 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

»
17 months 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

»
17 months 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.

  • »
    »
    17 months 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

  • »
    »
    17 months 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
»
17 months 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?

  • »
    »
    17 months 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

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

Getting TLE related to this: https://codeforces.me/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.

  • »
    »
    17 months 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

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

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

»
17 months 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)
»
17 months 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.

»
17 months 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?

»
17 months 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
  • »
    »
    17 months 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.

»
17 months 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

  • »
    »
    17 months 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.

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

      It's still $$$O(n^2logn)$$$ though but it passes

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

        How is it still n2logn?

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

        I think the other one doesnt pass since it recalculates the GCD for the same pair of numbers multiple times, maybe if you store them if calculated once so you don't calculate them again passes though.

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

          Yeah exactly. It's weird compiler optimizations. Also gcd(a,b) passes faster than __gcd(a,b)

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

Why was my first submission skipped?

  • »
    »
    17 months 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

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

Why frozen? I cant submit my code.

»
17 months 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

»
17 months 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?

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

Goofy ahh contest

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

Why is the standing still frozen?

»
17 months 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.

»
17 months 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.

»
17 months 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

  • »
    »
    17 months 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,

»
17 months 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.

  • »
    »
    17 months ago, hide # ^ |
     
    Vote: I like it +15 Vote: I do not like it
    Hint 1
    Hint 2
    Hint 3
»
17 months 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??

  • »
    »
    17 months 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

    • »
      »
      »
      17 months 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.

»
17 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
»
17 months 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.me/contest/2116/submission/322307127

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

  • »
    »
    17 months 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.

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

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

  • »
    »
    17 months 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.

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

Why is there no rating change dor div 1

»
17 months 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 :*)

  • »
    »
    17 months 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.

»
17 months 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.

»
17 months 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

  • »
    »
    17 months 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.

    • »
      »
      »
      17 months 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

    • »
      »
      »
      17 months 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.

»
17 months 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)
»
17 months 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 - Гелифиш и трёхцветная фиалка and 2116B - Гелифиш и гипсофила?

  • »
    »
    17 months 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

»
17 months 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.me/contest/2116/submission/322329033

»
17 months 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

  • »
    »
    17 months 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.

    • »
      »
      »
      17 months 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

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

can anyone tell me where to find editorial of this contest

»
17 months 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.

»
17 months 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?

»
17 months 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?

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

First reach CM!

»
17 months ago, hide # |
← Rev. 2  
Vote: I like it -31 Vote: I do not like it

.

»
17 months 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)
         
     
»
17 months 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?

»
17 months 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

»
17 months 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.me/contest/2116/submission/322288935

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

Please post editorial fast

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

when editorial

»
17 months 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

»
17 months 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?

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

    6 10 15 -> gcd(6, 10, 15) = 1 but You need 3 numbers(2 operations) to make 1

    You cannot make 1 directly with only 2 numbers because gcd(6, 10), gcd(10, 15), gcd(6, 15) != 1

    Thus, there are some cases that [total gcd is 1 & No co-prime pair exists.] I think pretest 9 is one of these cases.

»
17 months 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
»
17 months 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

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

Is it too hard to post editorial for this contest?

»
17 months 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.

»
17 months 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:(

»
17 months 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!

»
17 months 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.

»
17 months 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!

»
17 months 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