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

Автор BledDest, 6 лет назад, По-русски

1051A - Вася и пароль

Разбор
Код решения (Ajosteen)

1051B - Взаимно простые пары

Разбор
Код решения (PikMike)

1051C - Вася и мультимножества

Разбор
Код решения (Ajosteen)

1051D - Двураскраски

Разбор
Код решения (PikMike)

1051E - Вася и длинные числа

Разбор
Код решения (Ajosteen)

1051F - Самое короткое условие

Разбор
Код решения (Ajosteen)

1051G - Дистинктификация

Разбор
Код решения (BledDest)
  • Проголосовать: нравится
  • +39
  • Проголосовать: не нравится

»
6 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

It should be "If k is odd" in editorial of problem C

»
6 лет назад, # |
  Проголосовать: нравится +12 Проголосовать: не нравится

В разборе задачи F ошибка: Формула кратчайшего расстояния в дереве h[v] + h[u] — 2 * h[lca(u,v)]

»
6 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

In solution for E it should be ax + 1

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

Can anyone explain why the last coloumn won't contain the answer and how are we calculating final answer(why are we xoring with 3)?

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

    Hi there,

    I think you are talking about problem D.

    Well, the explanation skipped a step.

    BB — 00 BW — 01 WB — 10 WW — 11

    This is what the numbers mean.

    The number of new components can be easier to understand in my code here. Let me know if you have any doubts or require further explanation. :)

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

      please , would you like to explain with 1 ,2,3 test case

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

      Hi ghoshsai5000, Thanks for simplifyinh things.could you help me with one doubt on author's editorial:

      int get(int mask, int nmask){
      	int cnt = __builtin_popcount(mask ^ nmask);
      	if (cnt == 0) return 0;
      	if (cnt == 2) return (full(mask) ? 1 : 2);
              // Please explain this return statementt, based on your code, it should 
             //be: return (full(mask) ? 1 : 0);
      	return (full(mask) ? 0 : 1);
      }
      

      If you can explainn this by any example, that would be great. Thanks :)

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

        Hi,

        Being honest, I didn't understand the editorial code completely. That's why I clearly elaborated all 16 cases in my code with understandable variable names to make the logic extremely clear :)

»
6 лет назад, # |
  Проголосовать: нравится +7 Проголосовать: не нравится

Proof of complexity of F?

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

    Assume M = O(N), since M <= N + 21. Then, the complexity will be something like O((21*N*lg N + Q * (lg N + 21)). Since the preprocessing part for LCA takes O(N lg N) time and no more than O(N) edges will be erased from the set. We run dijkstra (O(N lg N)) from no more than 21 vertices = O(21*N lg(N)) and for every query we find the lca in O(lg N) and then iterate over all atmost 21 bad vertices to compute each distance in a O(1) time.

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

Here's my code for problem F, I'm not sure why I get WA on test 3 everything seems ok to me. can someone please explain my mistake? 43225756

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

In problem C, i found test case 6 1 1 1 2 2 2 that your solution print A A A A A A, can you recheck it ?

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

Why didn't CodeForces evaluate the code? What's wrong?

»
6 лет назад, # |
  Проголосовать: нравится +22 Проголосовать: не нравится

We can use a type of mergeable segment tree to solve problem G, with O(nlogn) nodes created overall, so the time complexity is O(nlogn).

http://codeforces.com/contest/1051/submission/43232839

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

Can someone explain the Question D. Thanks!

»
6 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

Hard to understand Problem D. Can anyone Suggest me some good Editorial.

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

In problem D like the editorial says dp[i][j][mask] be the number of beautiful bicolorings of the first i columns such that j components are already created and can't be modified and the colors of the i-th column are determined by mask. I didn't understand what does mask mean, like what does dp[2][4][0] mean. I wanted to know that ,like dp[2][4][0] mean number of beautiful bicolorings of the first 2 coulmns such that 4 components are already visited , now what does 0 mean here. Someone please explain.

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    Set dp[n][k][mask] as the number of ways with n columns, k components, ending with mask in the n-th column. You can end up in 4 ways: white-white, white-black, black-white, black-black (that's the meaning of the mask having the values 00, 01, 10, 11). After this, try to figure it out the dp transitions by yourself. Good luck

  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    Video solution with explanation: https://youtu.be/lSyQQ1T6iQ8

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

hey can someone tell me what's the wrong with this code for problem C ? link — http://codeforces.com/contest/1051/submission/43270735 thanks in advance.....

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

Can someone help me out with what is test 67 on problem E or why my code is going wrong?

43274362

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

    Sorry, after thinking I realized I was just running into anti-hash tests. I was lazy and chose 998244353 as my hashing prime, and the same code AC with 1e9+9.

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

      I advise you to use double MODs because if this submission was in a contest anyone can hack you.

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

В задаче D допущена ошибка:

Начальные состояния — dp[0][0][mask] = 1;

Правильный вариант

dp[1][0][mask] = 1;

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

My submission in "E — Vasya and Big Integers" was TLE, can anyone help me?

http://codeforces.com/contest/1051/submission/43280760

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

In problem D , what if value of n was about 10^8 .Is it possible to derive a combinatorial formula to solve it in that case?

»
4 года назад, # |
  Проголосовать: нравится +10 Проголосовать: не нравится

There's an even faster solution for problem D.

Let $$$ww[i][j]$$$ denote the number of $$$2 \times i$$$ grids that end with a column of (two) white squares and have $$$j$$$ components. Define $$$wb[i][j]$$$, $$$bw[i][j]$$$ and $$$bb[i][j]$$$ analogously.

Now, suppose we have a random $$$2 \times (i-1)$$$ grid and we want to find out the value of $$$ww[i][j]$$$. Consider the possible arrangements of the $$$i-1$$$-th column in the random grids:

1) The $$$i-1$$$-th column contains two white squares. In this case, we add $$$ww[i-1][j]$$$ to $$$ww[i][j]$$$. We do this because every possible grid that ends with two white squares and has $$$j$$$ components generates another possible grid (which has one more column and keeps the same amount of components) by adding a column of white squares.

2) The $$$i-1$$$-th column contains two black squares. In this case, we add $$$bb[i-1][j-1]$$$ to $$$ww[i][j]$$$ (notice that we add one column and one component to the grid when we add a column of white squares).

3) The $$$i-1$$$-th column contains distinct squares. In this case, we add $$$wb[i-1][j]$$$ and $$$bw[i-1][j]$$$ to $$$ww[i][j]$$$. This happens because when we add a column of white squares, the number of components doesn't change (the white part of the $$$i-1$$$-th column touches the new column) and, obviously, the number of columns increases by 1.

This means that

$$$ww[i][j] = wb[i-1][j] + bw[i-1][j] + ww[i-1][j] + bb[i-1][j-1] $$$

The other recurrences are left as an exercise to the reader $\dots$

Obs.: Notice that $$$ww[i][j] = bb[i][j]$$$ and $$$wb[i][j] = bw[j][i]$$$ because of symmetry. I only used four distinct arrays in this comment because my reasoning can be expressed more clearly this way.

Therefore, you just need to run a double for loop to update the DP arrays. This can be achieved in $$$O(n \cdot k)$$$ time.

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

Question D java solution

import java.util.*;
public class Main{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int mod=998244353;
        int n=sc.nextInt(),k=sc.nextInt();
        long ans[][][]=new long[n][4][k+5];
        //one number condition
        ans[0][0][1]=1;
        ans[0][1][2]=1;
        ans[0][2][2]=1;
        ans[0][3][1]=1;
        //then multiple number condition
        for(int i=1;i<n;i++){
            for(int j=1;j<=k;j++){
                ans[i][0][j]=(ans[i-1][0][j]+ans[i-1][1][j]+ans[i-1][2][j]+ans[i-1][3][j-1])%mod;
                ans[i][1][j]=(ans[i-1][0][j-1]+ans[i-1][1][j]+ans[i-1][3][j-1]+(j>1?ans[i-1][2][j-2]:0))%mod;
                ans[i][2][j]=(ans[i-1][0][j-1]+ans[i-1][3][j-1]+ans[i-1][2][j]+(j>1?ans[i-1][1][j-2]:0))%mod;
                ans[i][3][j]=(ans[i-1][3][j]+ans[i-1][1][j]+ans[i-1][2][j]+ans[i-1][0][j-1])%mod;
            }
        }
        System.out.print((ans[n-1][0][k]+ans[n-1][1][k]+ans[n-1][2][k]+ans[n-1][3][k])%mod);
    }
}