Proof_by_QED's blog

By Proof_by_QED, 13 months ago, In English
Rating Predictions

Thanks to reirugan for helping write the editorials.

2094A - Trippi Troppi

Problem Credits: Proof_by_QED

Solution
Code
Rate The Problem!

2094B - Bobritto Bandito

Problem Credits: Proof_by_QED

Hint
Solution
Code
Rate The Problem!

2094C - Brr Brrr Patapim

Problem Credits: cry

Hint
Solution
Code
Rate The Problem!

2094D - Tung Tung Sahur

Problem Credits: Proof_by_QED

Hint
Solution
Code
Rate The Problem!

2094E - Boneca Ambalabu

Problem Credits: Proof_by_QED

Hint 1
Hint 2
Solution
Code
Rate The Problem!

2094F - Trulimero Trulicina

Problem Credits: Proof_by_QED

Hint
Solution
Code
Rate The Problem!

2094G - Chimpanzini Bananini

Problem Credits: Proof_by_QED, cry

Hint 1
Hint 2
Solution
Code
Rate The Problem!

2094H - La Vaca Saturno Saturnita

Problem Credits: cry

Hint 1
Hint 2
Solution
Code
Rate The Problem!
  • Vote: I like it
  • +90
  • Vote: I do not like it

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

I hope you all enjoyed the contest!

This is my first time writing an editorial — please let me know if there's anything unclear (or any mistakes). I'll read all of the replies to this comment and make any edits as necessary.

P.S. Thanks to temporary1 for proofreading, and for suggesting the optimizations on H.

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

    temporary1 doing a serious thing? I don't believe you for a second.

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

    The tutorial is very intuitive and easy to follow, as my solutions happen to match the tutorial ones on all the problems. I enjoy the whole set, particularly G and H as they offer challenges but not too hard for div 4. Thanks for the quick tutorial!

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

    For hint 2 for problem G:

    "It suffices to keep track of the current score, the score of the array if it were backwards, the size of the array, and the sum of the array."

    No. You also need to know the last element.

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

      In Hint 1, it says that we will be using a deque. In Hint 2, I ask what other values we have to maintain. These are the only other values we need to maintain; the last element is already being tracked by the deque.

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

        What does "other" mean when you say "other values"? If you don't count the 'last element', why do you count 'the size'; isn't that also 'being tracked by the deque'?

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

          You're right that in most languages, the standard library deque supports constant-time access of size, so it doesn't really have to be maintained. But technically a deque is just a data structure which supports pushing/popping and accessing on both ends — it doesn't by definition necessarily support size.

          In any case, does a small wording difference like this really matter so much?

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

            I don't view it as wording (otherwise I wouldn't be commenting about it). The size and sum of the array are very trivial to maintain. The problem, to me, was all about how to maintain the last element. Using two deques is clever and smarter than what I did.

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

              You shouldn't need two deques, only one. (You can use two deques if you want, but the solution I presented only uses one.)

              The idea of using a deque is in Hint 1, so I think semantically it's not necessary to include in Hint 2.

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

    Loved the editorial, but(just interested) do the names of the problems have ANYTHING to do with the problem, or solution perhaps?

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

H is hard for me ;-;

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

Got filtered hard by F, but in hindsight it feels very simple...

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

One of the best Contest :)

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

This is a nice problem like H

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

liked the problems.. couldn't finish H in time, but the contest was well balanced! :)

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

code for e also, please.

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

In F I tried to fill the board in chess board manner, like filling all the black squares first and then all the white squares, what is the problem with this approach?

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

    maybe number of elements are not same. share exacxt approach?

    • »
      »
      »
      13 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it
      // this is the code
      int main()
      {
          fast;
          ll t;
          cin>>t;
          while(t--)
          {
              ll n, m, lmao;
              cin>>n>>m>>lmao;
      
              ll count = (n*m)/lmao;
      
              vector<pair<ll, ll>> numbers;
              for(int i = 1;i<=lmao;i++) numbers.push_back({i, count});
      
              vector<vector<ll>> grid(n, vector<ll>(m ,0));
      
              int k = 0;
              for(int i = 0;i<n;i++)
              {
                  int start = 1;
                  if((i%2) == 0) start = 0;
      
                  for(int j = start;j<m;j+=2)
                  {
                      grid[i][j] = numbers[k].first;
                      numbers[k].second--;
                      if(numbers[k].second == 0) k++;
                  }
              }
      
              for(int i = 0;i<n;i++)
              {
                  int start = 0;
                  if((i%2) == 0) start = 1;
      
                  for(int j = start;j<m;j+=2)
                  {
                      grid[i][j] = numbers[k].first;
                      numbers[k].second--;
                      if(numbers[k].second == 0) k++;
                  }
              }
      
              for(int i = 0;i<n;i++)
              {
                  for(int j = 0;j<m;j++)
                  {
                      cout<<grid[i][j]<<" ";
                  }
                  cout<<endl;
              }
          }
          return 0;
      }
      
      • »
        »
        »
        »
        13 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        ofc ll is long long, didnt attach that piece of code, and lmao is the k given in question

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

        I had a very similar implementation. I saw that it didn't work. In this case row is n and col is m: I said: if (n < m) { swap(n, m); switched = true; }

        then at the end I dealt with printing the normal ones and the switched ones as two separate cases so I can get them back in format. It worked.. I don't know why this WOULD work, though. My submission (PASCALABC.NET): 320834015

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

      i had the exact same idea but i found a test which fails. it was 2 rows and then something i dont really remember

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

i agree with SpyrosAliv, F was indeed 3500

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

who the hell predicted F 3500

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

Why is the time for query in H O(sqrt(k)+d(k)logn)? Shouldn't it be more since we have to go for every divisor not only for k, but for k',k'' and so on?

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

I have yet another optimization for H: 315473086. Instead of binary searching, you can store a queue of positions greater than or equal to the current. Then, you can access its first element in constant time. This requires you to process queries offline and in parallel: perform one jump for all queries starting at the current position before removing it from the queue.

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

Anyone who wants video solutions, can check out my screencast of this contest along with the solution explanations: https://www.youtube.com/watch?v=8WPZwkMQWng

(My solution to H is the same as the editorial but I didn't think it was neat enough, so I tried reallly hard to come up with another solution for that, but couldn't, and ultimately implemented the editorial solution)

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

i've done pretty much the same as editorial but still got TLE https://mirror.codeforces.com/contest/2094/submission/315487879 can anyone help pointing out which part is probably taking too long?

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

Did anyone notice the names of the problems? Very funny to be honest.

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

F is insane

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

macaquedev and SpyrosAliv claiming 900 and 3500 for F respectively is crazy lmao

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

    It was a trivial problem for me. I saw the statement, and instantly saw the solution.... The only thing stopping me from writing 800 was the fact that the implementation is too long for 800.

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

It is very good round! But i think, G and H are easier that task F. I can`t solve constructivities(

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

Can someone explain to me, In problem F, why can not I fill the grid in chess board manner. I have tried so many testcases.315463534

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

    Consider n=2, m=3 and k=3.

    Output will be:

    1 2 1

    3 2 3

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

    2 6 3

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

      Ohh got it, Thankyou!

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

        regardless of the parity of n and m, for this strategy to work we want nm/3 < (m(n-1)/2) + 1 because for k = 2 it always pass if nm/3 < rhs nm/4 also follows

        nm/3 < m(n-1)/2 + 1

        nm/3 <= m(n-1)/2

        n/3 <= (n-1)/2

        2n <= 3n — 3

        n >= 3

        solution only works for n >= 3. what is (m(n-1)/2) + 1 if your doubt, just start coloring some square from bottom go up and count the no of cells the first time they touch. like this

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

This is the first time I fail a problem because of declaring a vector locally instead of globally [H]. After getting the first TLE, I just assumed that what I was doing wasn't efficient enough and never thought to check for something as stupid as that... I guess for future reference, think more about what should be global and what shouldn't? But still, I can't believe I actually missed that.

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

    Same here, I switched from map to vector of length 1e5 + 1 for each test case after my first TLE thinking it would be a harmless optimization, turns out it was the opposite.

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

    Shalom

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

    It's essentially the same thing as using memset for the whole array, which thousands of people do every contest :)

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

Damn it i found out F as constructive then quite it after 15 mins,then tried G and got my ass whooped throughout the contest by solving some equation.Turns out F was straightforward but NGL macaquedev must be tripping to rate it at 900.

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

As the Balon D'or winner, this contest was quite good, F was quite difficult however trivial once realised.

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

can someone explain why 315500513 is getting tle while 315500630 is not.

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

    During a naive Python explanation, it does take more time to access a global variable than a local variable.

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

Problem G uses the same trick as a problem I posted on Luogu in 2020: https://www.luogu.com.cn/problem/P6823

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

In problem D, I tried different approaches, but I got the wrong answer or TLE every time. Can anyone help me to solve this

My submission-(https://mirror.codeforces.com/contest/2094/submission/315460141)

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

If you prune the divisors after each iteration, and combined with offline processing, you can get $$$O(d)$$$ for each query.

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

cry seems to love √N observations :) As a bit of context, first we got P2 on 2025 USACO US Open Gold[hardest problem in the contest], and we've also got H on this contest[also the hardest problem].

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

who wrote such a good second pretest at d bro?? like i spent 95 minutes on the problem and couldnt solve it

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

    I tried to map the l and r from p to s, and was also stuck at test 2. I used the logic that say if I have an l in p, and one or two in s, then the l in p will be mapped to the l's in s. Then if there is an r next in p and s, the cycle will continue. But this will fail for the simple test case ,"LL LL" as the program counts the two l's in s as mapped from the first l in p, and gives an error as an l will be left in p. Did you use the same logic? 315469519

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

I used following approach for 2094F - Trulimero Trulicina

We aim to construct an $$$n \times m$$$ grid using integers from $$$1$$$ to $$$k$$$, each appearing exactly $$$\frac{n \cdot m}{k}$$$ times, with no two adjacent cells having the same value.


When one of the dimensions is divisible by $$$k$$$:

  • Case A: $$$( n \bmod k = 0 ) $$$

    • Fill the grid column-wise using: a[i][j] = ((i + j) % k) + 1
    • The offset changes per column to ensure adjacent cells differ.
  • Case B: $$$( m \bmod k = 0 )$$$

    • Fill the grid row-wise using: a[i][j] = ((j + i) % k) + 1

These cyclic patterns rotate values so that no adjacent cells share the same value.


When neither $$$n$$$ nor $$$m$$$ is divisible by $$$k$$$:

  • Factor $$$k$$$ into two integers $$$nn$$$ and $$$mm$$$ such that:

    • $$$nn \cdot mm = k$$$
    • $$$nn \mid n$$$ and $$$mm \mid m$$$
    • $$$nn \geq 2$$$, $$$mm \geq 2$$$ This ensures the tile is at least $$$( 2 \times 2 )$$$, avoiding adjacency conflicts.
  • Steps:

    • Build a tile of size $$$nn \times mm$$$ filled with values from $$$1$$$ to $$$k$$$.
    • Replicate the tile across the grid using: a[i][j] = tile[i % nn][j % mm]

This guarantees: Equal frequency and no two adjacent cells share the same value.


Summary

  • Use cyclic shifts when $$$n$$$ or $$$m$$$ is divisible by $$$k$$$.
  • Use $$$(\geq 2)$$$ $$$\times$$$ $$$(\geq 2)$$$ tiling when neither is divisible.

Check 315555434 for implementation if you wish to :D

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

We can avoid using an additional deque by simply maintaining a boolean flag to track whether the current state is reversed or not in 2094G - Chimpanzini Bananini.

Check the submission for reference : 315552863

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

Shouldn't there be multiple solutions of B?

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

I have a solution for 2094H - La Vaca Saturno Saturnita with a better bound.

Precompute divisors of all numbers in $$$\mathcal{O}(A \log A)$$$.

Each query will be processed in this way:

  1. Iterate all divisors of current $$$k$$$ and find the closest element to the right that is a divisor of $$$k$$$
  2. Jump to that element and add $$$k \cdot (i_2 - i_1)$$$ to answer
  3. Apply described loop operation naively on the dividing element reducing $$$k$$$ to $$$k'$$$
  4. Add $$$k'$$$ to answer and advance by $$$1$$$ position
  5. Repeat until we have reached $$$r$$$

Process all queries in parallel, so that information about closest element with given value is available in $$$\mathcal{O}(1)$$$ for all values at any point.

This operation

while k is divisible by a[i]:
    k := k/a[i]

has $$$2$$$ limitations:

(1) It reduces the value of $$$k$$$ by at least twice on each iteration. It applies the limit on total number of loop iterations as $$$\mathcal{O}(\log k)$$$. This is also the limit on number of jumps.

(2) It reduces the number of divisors of $$$k$$$ or by at least twice after all iterations on a single element $$$a[i]$$$. Consider factorizations of $$$k$$$ and $$$a[i]$$$

$$$F(k, p) = (1 + F(k/p, p)) \;\textrm{if}\; k \bmod p = 0 \;\textrm{else}\; 0$$$

$$$k = \prod\limits_{p \in \mathbb{P}} \textrm{pow}(p, F(k, p))$$$

$$$d(k) = \prod\limits_{p \in \mathbb{P}} 1 + F(k, p)$$$

For any $$$k$$$ and $$$a[i]$$$ that $$$k \bmod a[i] = 0$$$ there exists such prime $$$p$$$ that

$$$F(k', p) = F(k, p) \% F(a[i], p)$$$

then

$$$2 \cdot F(k', p) \lt F(k, p)$$$

$$$2 \cdot (F(k', p) + 1) \leqslant F(k, p) + 1$$$

$$$2 \cdot d(k') \leqslant d(k)$$$

Thus instead of $$$\log k$$$ jumps $$$\mathcal{O}(d(k))$$$ each, we actually have $$$d(k) + d(k') + d(k' ') + \ldots = d(k) + d(k)/2 + d(k)/4 + \ldots = \sum\limits_{i=0}^{log_2 k} \frac{d(k)}{2^i} \lt 2 \cdot d(k)$$$

Compexity per query is then $$$\mathcal{O}(\log k + d(k))$$$. Total complexity is then $$$\mathcal{O}(A \log A + q \log k + q \cdot d(k))$$$

315489102

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

I am not clear with solution and approach of problem H not understanding very easily can u make simple reirugan

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

where is Tralalero Tralala?

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

Where are ballerina capuchina and bombordiro crocodilo problems. They are the GOAT.

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

Easy problems, should've put bombardiro crocodilo instead

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

For 2094C — Brr Brrr Patapim ----- More optimised Code than the editorial one

void solve(){
    int n;
    cin>>n;
    vector<vector<int>>mat(n,vector<int>(n));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>mat[i][j];
        }
    }

    // main
    
    vector<int>ans(2*n);
    int actualSum=2*n*(2*n+1)/2;
    int sum=0,k=1;

    for(int j=0;j<n;j++){
        ans[k++]=mat[0][j];
        sum += mat[0][j];
    } 
    for(int i=1;i<n;i++){
        ans[k++]=mat[i][n-1];
        sum += mat[i][n-1];
    }
    ans[0] = actualSum - sum;

    for(int i=0;i<2*n;i++) cout<<ans[i]<<" ";
    cout<<"\n";
}

Using the logic of missing number to find the p1

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

H is a very good question, and I didn't think of the approach at all.

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

Is l in Problem B always less than or equal to diff? If so, what's the point of this condition?

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

what the fuck are these names br0.