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

Автор Vladosiya, история, 4 года назад, перевод, По-русски

1714A - Все любят спать

Идея: Vladosiya

Разбор
Решение

1714B - Удали префикс

Идея: MikeMirzayanov

Разбор
Решение

1714C - Минимальное разнообразное число

Идея: MikeMirzayanov

Разбор
Решение

1714D - Покрась вхождениями

Идея: MikeMirzayanov

Разбор
Решение

1714E - Прибавление по модулю 10

Идея: ibraevdmitriy

Разбор
Решение

1714F - Построй дерево и точка

Идея: MikeMirzayanov

Разбор
Решение

1714G - Префиксы путей

Идея: MikeMirzayanov

Разбор
Решение
Разбор задач Codeforces Round 811 (Div. 3)
  • Проголосовать: нравится
  • +22
  • Проголосовать: не нравится

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

Code for D is messed up a bit.

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

    I implemented it in an easier way.

    My Submission
    • »
      »
      »
      6 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится
      #include<bits/stdc++.h>
      using namespace std;
      using ll=long long;
      int main() {
          ll t;
          cin >> t;
          while(t--) {
             ll n;
             cin>>n;
             vector<ll> arr(n);
             for(ll i=0;i<n;i++) {
                 cin>> arr[i];
             }   
             set<ll> st1={1,2,4,8};
             set<ll> st2={3,6,7};
             for(ll i=0;i<n;i++) {
                 if(arr[i]%10==0) arr[i]=2*(arr[i]/10)-1;
                 else if(arr[i]%5==0) arr[i]=arr[i]/5;
                 else if(arr[i]%10==9) arr[i]=-5;
               
                else if((arr[i]/10)%2==0 && st1.count(arr[i]%10)) {
                    arr[i]=-10;
                    
                }
                else if((arr[i]/10)%2==0 && st2.count(arr[i]%10)) {
                     arr[i]=-5;
                }
               else if((arr[i]/10)%2!=0 && st2.count(arr[i]%10)) {
                   arr[i]=-10;
               }
               else {
                   arr[i]=-5;
               }
             }
             bool brk=false;
             for(ll i=0;i<n-1;i++) {
                 if(arr[i]!=arr[i+1]) {
                     brk=true;
                     break;
                 }
             }
             if(brk) {
                 cout <<"NO\n";
             }
             else cout <<"YES\n";
             
          }
          
          
          
         
          }
      

      why this code is wrong can you please tell

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

Mike Mirzayanov thanks for awesome editorial

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

Question D is a great problem,but why is the code for D so messy?

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

How to solve question D with DP? Can you tell me about it and share your code? If you can help me, I will thank you very much.

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

Indented solution of problem D from editorial:

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

"When you color a letter in red again, it stays red."

Missed this line during contest does this make the question similar to Jump game? ->where we can jump from index to any index in range (i,i+a[i])

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

The code for F: Build a Tree and That is it does not really clarify things mentioned in tutorial rather it has checks and implementations that makes it seem like the code to be working on a different idea. Can anyone either explain the tutorial or the code ? Thanks.

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

    Can you help me with G.I checked ur code, but can't understand, Can u explain ur idea ? Thanks.

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

      So, let's first make a DFS call and make array Asum[N], where Asum[u] stores the sum of all the A-values along the edges from root to node u.

      Now notice that B values of all edges are positive. Let's pick any node u. And let's say, Path[u] = [B1, B2, B3, B4, B5,.....Bx] where the Bi indicates the B-values of all edges from root to node u.

      Since Bi s are positive the prefix sum on Path[u] will only increase. Let's call the prefix sum on Path[u] as PrefixPath[u].

      Since we want to know maximum prefix path that doesnt go beyond all A values sum in the path from root to u, the final answer for node u will be

      Answer[u] = Largest index k in PrefixPath[u] such that PrefixPath[k] > Asum[u].

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

    I can explain my idea of solution if it can help you.

    Let's place $$$1,2$$$ and $$$3$$$ nodes. There is $$$4$$$ possible ways to do it: link to image

    1. The first case: $$$d_{23} = d_{31} + d_{12}$$$. Let's check it, if it is right, then let's build our tree like in image.

    2. The second case: $$$d_{31} = d_{23} + d_{12}$$$. Let's check it, if it is right, then let's build our tree like in image.

    3. The third case: $$$d_{12} = d_{23} + d_{31}$$$. Let's check it, if it is right, then let's build our tree like in image.

    4. The last case: let's see that $$$d_{12} + d_{23} + d_{31} \le n$$$, let's get loop for $$$d_{14} = [1..n]$$$ (sum of $$$n$$$ for all cases is $$$\le 10^5$$$ so we can do it), now we know $$$d_{34} = d_{31} - d_{14}$$$ etc. If all this right, then let's build our tree like in image.

    If all cases are wrong, answer is NO.

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

My Editorial for the problems I solved

A
B
C
D
E
»
4 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

It was a very good contest D was interesting but i think you should reorder the problem like this B C A E D G F

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

I read the solution "Thus, we will apply the operation to each element of the array until its remainder modulo 10 becomes, for example, 2, and then check that the array does not contain both remainders 2 and 12 modulo 20." I don't know why do we need to check that "the aray does not contain both remainders 2 and 12 modulo 20". Why do we have to do that. Can you explain for me. Thanks

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

    There are only 2 possible cycles when considered modulo 20 (2 -> 4 -> 8 -> 16 -> 2) and (12 -> 14 -> 18 -> 6 -> 12). If members of both cycles are present, you can never make all the numbers the same.

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

Code for $$$Problem D$$$ should be posted like this :

Solution

I think Vladosiya has forgotten to write </spoiler> at the end.

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

In problem E, why flag12 and flag2 should not be true for the answer to be YES?

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

Why I got TLE ? What's wrong with my code[submission:166546367]

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

Is there a way to solve G using binary lifting

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

Could someone explain why this submission for G of mine get TLE ? I know it's inefficient but I still don't get why it doesn't work

First I do a dfs to precompute all prefix sums for a and b. Then for each leaf I find the path from it to the root, reverse the path, and use binary search for each vertices on the path to get the answer.

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

Hi can anyone help me figure out why my code for D is wrong? Thanks a lot! Basically I have tried to iteratively find the places with maximum coverage. However, it gives WA on a later TC.

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

Could someone tell me what's wrong with my solution for G here? I tried all the combos of lb/ub but test case 4 is WA each time.

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

THIS IS MOST EASIEST AND UNDERSTANDABLE CODE FOR THE QUESTION E -> AND I AM PROUD OF IT I DID IT IN FIRST TRY AS A < 1500 RATED .

void solve(){
   int n;  
   cin >> n; 
   vi a(n); ;
   read(a);
      for(int i =0; i<n; i++){
        if(a[i] % 10 == 0 || a[i] % 5  == 0){
            a[i] += a[i] % 10;
        }else{
            while(a[i] % 10 != 6){
                a[i] += a[i] % 10;
            }
            a[i] %= 20;
        }
      }
    if( n == count(all(a), a[0])) yes();
    else no();
}