Блог пользователя Proof_by_QED

Автор Proof_by_QED, 13 месяцев назад, По-английски
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!
Разбор задач Codeforces Round 1017 (Div. 4)
  • Проголосовать: нравится
  • +90
  • Проголосовать: не нравится

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +44 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

H is hard for me ;-;

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

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

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

One of the best Contest :)

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

This is a nice problem like H

Spoiler
»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

code for e also, please.

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

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

    • »
      »
      »
      13 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится
      // 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 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      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 месяцев назад, скрыть # |
 
Проголосовать: нравится +9 Проголосовать: не нравится

i agree with SpyrosAliv, F was indeed 3500

»
13 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится +1 Проголосовать: не нравится

who the hell predicted F 3500

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

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

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

F is insane

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

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

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

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

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    13 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

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

    Spoiler
»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # |
Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

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

Proof
»
13 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится +3 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Shouldn't there be multiple solutions of B?

»
13 месяцев назад, скрыть # |
Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # |
Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

where is Tralalero Tralala?

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Easy problems, should've put bombardiro crocodilo instead

»
9 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
5 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
5 недель назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

what the fuck are these names br0.