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

Автор zwezdinv, история, 21 месяц назад, перевод, По-русски

Спасибо за участие!

1994A - Разнообразная игра

Разбор
Код

1994B - Веселая игра

Разбор
Код

1994C - Голодные игры

Разбор
Код

1994D - Смешная игра

Подсказка
Разбор
Код

1994E - Деревянная игра

Подсказка
Подсказка.ответ
Подсказка.доказательство
Разбор
Код

1994F - Stardew Valley

Разбор
Код

1994G - Minecraft

Подсказка 1
Подсказка 2
Подсказка 3
Разбор
Код

1994H - Fortnite

Разбор
Код
  • Проголосовать: нравится
  • -129
  • Проголосовать: не нравится

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

D is a cute problem

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

What is E?

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

Why are people down voting?

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

Editorial is so fast.Thank You!

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

CDE are very nice

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

the editorial came faster than my girlfriend

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

thank you for fast editorial

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

Think of the most stupid solution you can do

Great editorial for problem G

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

C is also solvable in $$$O(n)$$$ using two pointers.

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

    Yeah I tried it using two pointers but got wrong answer on 776th number of test case 2. Can you check my code, where am I wrong?

        cin >> n >> k;
        vll v(n), zero(n + 1, 0);
     
        rep(i,0,n) cin >> v[i];
     
        rep(i,0,n){
            sum += v[i];
            if(sum > k) {
                sum = 0;
                zero[i] = 1;
            }
        }
     
        per(i,n - 1,0){
            if(zero[i]) zero[i] = zero[i + 1] + 1;
            else zero[i] = zero[i + 1];
        }
     
        // rep(i,0,n) cout << zero[i] << " ";
        // cout << nL;
     
        sum = 0;
        l = 0;
        r = 0;
        while(l < n){
             while(r < n && sum + v[r] <= k){
                sum += v[r++];
            }
            
            ans += ((n - r - 1) - (r < n - 1 ? (zero[r + 1]) : (0))) + (r - l);
            // cout << r << " ";
            sum -= v[l++];
            if(r == n && sum <= k) ans++;
            // cout << ans << " " << l << nL;
        }
       
        cout << ans << nL;
       
    
  • »
    »
    21 месяц назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    can you please explain how?

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

    This is my code: 271271875

    So if we start at mushroom $$$i$$$ with $$$g=0$$$ before performing any operations we will hit $$$g=0$$$ again at some $$$j\geq{i}$$$.

    There might be multiple possible values of $$$j$$$ for $$$i$$$ since $$$g$$$ might become zero multiple times over and over again.

    We only need to calculate the smallest such $$$j$$$. Let that number be $$$l_i$$$.

    If $$$j$$$ doesn't exist that means we got to the end of the array and still $$$g\leq{x}$$$. In that case we can assign $$$l_i=-1$$$.

    Code to calculate array l

    Now if we choose $$$l=i$$$, $$$r$$$ can't be $$$l_i$$$ because in that case g will result in zero. Now if we choose $$$l=i$$$, $$$r$$$ can't be $$$l_i$$$ because in that case g will result in zero.

    But $$$l_i$$$ is not the only $$$r$$$ we aren't allowed to pick. Lets say we don't pick $$$r=l_i$$$ and instead go further. Next index $$$k$$$ when $$$g$$$ will hit $$$0$$$ will be

    Spoiler

    Now let $$$dp_i$$$ represent how many values $$$r\geq{i}$$$ we can't pick. The transition is $$$dp_i=1+dp_{l_i+1}$$$. Array $$$dp$$$ can be calculated in $$$O(n)$$$ by for loop going from last to first element.

    Now we will for every $$$1\leq{l}\leq{n}$$$ calculate the number of possible values of $$$r$$$. It is equal to $$$n-l-dp_l$$$ (0-indexed). The total sum is the answer.

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

    i did like this,idk what is the issue

    cant we solve problem C like this-

    1.first applying sliding window and count all the subarras having toxicity less then equal to x.

    now it said process can continue and we have to see if at last it is not zero,so we calculate the min element less then or equal to x from end of the array, let kth posn.

    2.and then again applying sliding window from start to kth posn to find all subarray whose sum>x.

    then just add both 1 and 2.

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

for B According to given solution if s = 010000 and t = 001111 then answer is "NO" but actually answer is "YES" . Please correct me if I am missing any thing.

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

Personally, I think $$$E$$$ should be should be placed as $$$C$$$, as it only requires knowing about OR, which is pretty popular as a simple adhoc problem.

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

«Компьютерная игра определяется числом x — максимальным уровнем отравленности в любой момент времени.»

раунд хороший, но в задаче С я подумал, что Х изменяется на максимальную отравленность, после чего отравленность сбрасывается:(

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

Another idea for A:

we use the fact that x != (x+1), so we set b[i][j]=a[i][j]+1 and if a[i][j]=(n*m) we make b[i][j]=1.

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

I totally did not guess D, and wrote wrong solution for E but luckily I had some bugs so it passed.

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

Thanks for fast editorial!

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

Any Minecraft players :D

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

Easier sol for A: 271203621

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

can anyone explain the approach of c with two pointers without DP

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

    you have to dp some way or the other

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

    If we choose i as l, we have maximum n-i choices for r. (0<=i<n). When we take i as I and r as n-1 and if we calculate g for all positions from i to n-1, we may encounter ct positions where g is zero. This is a significant finding, as it means there are ct indices that cannot be r if i is chosen as l. To keep track of this crucial information, we introduce an array c[n], which stores the number of zeros encountered when i is chosen as I and r is chosen as n-1. Now, we only need to find array c[n]. Now, we will define an array sum[n], which will store g if we calculate it backward from n-1 to 0. Lets say the resulting array is something like this [-,-,-,-,0,-,-,-,0-,-,-,-] let say the position of zeros be x and y, (y>x). So for all indices x<i<=y, we take i as l and n-1 as r, then we will encounter only one position with g equals zero. Similarly, for all 0<=l<=x and r=n-1, we will encounter two indices with g=0. Extend this to a general case, and we have an array that gives c[i] (number of indices at which g=0 if l=i and r=n-1). Then we have ans=summation(n-i-c[i]).

    #include<bits/stdc++.h>
    using namespace std;
    int main(){
        ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
        int t;
        cin>>t;
        while(t--){
            int n,x;
            cin>>n>>x;
            int arr[n];
            for(int i(0);i<n;++i) cin>>arr[i];
            int sum[n]={0};
            int c[n]={0}; // counts the number of zeros from i to n-1
            sum[n-1]=arr[n-1];
            int ct=0; // counts number of zeros
            long long ans=0;
            for(int i(n-1);i>=0;--i){
                if(i!=(n-1)){
                    sum[i]=(arr[i]+sum[i+1]);
                    c[i]=c[i+1];
                }
                if(sum[i]>x) sum[i]=0;
                if(sum[i]==0){
                    ++ct;
                    c[i]=ct;
                }
            }
            for(int i(0);i<n;++i){
                ans+=(n-c[i]-i);
            }
    
            cout<<ans<<endl;
        }
    
        return 0;
    }
    
»
21 месяц назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

Editorial of F: "Lets solve independently for each component." Task statement of F: "It is guaranteed that you can reach any house from any other by walking on the roads with NPCs only."

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

Thank you for fast editorial!

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

D was a really cool problem. orz

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

Can somebody please explain why my solution for D is getting accepted. I have literally zero idea (according to me, it should have given TLE).
Here is the link: 271248022
Any help would be appreciated.

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

help me, why we need to solve from end in problem C ?

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

    dp(i) means count of all good subarrays with i as starting point which is easier to do as transition is O(1) time comp. while if we take for dp(i) as count of good subarrays such that ending at i then transitions are not possible in O(1) but O(n) complexity as there are continuous ranges of index one or more j<=i at which we can always end at i with a nonzero value.

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

For Problem 1994E - Wooden Game we could also sort tree sizes decreasingly, and then add each one to the answer if it adds bits for all possible highest positions, checking with (ans | size) == (ans ^ size), and decreasing size until this requirement is met.

a = readTreeSizes()
sortDecreasingly(a)
ans = 0
for (size in a) {
    while ((ans | size) != (ans ^ size)) {
        size--
    }
    ans |= size
}
println(ans)
»
21 месяц назад, скрыть # |
 
Проголосовать: нравится +12 Проголосовать: не нравится

What's $$$mod$$$ in the editorial to H?

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

G < F I think, but I have another solution with simple dp.

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

Must D has a sulution?Why don't I see "No" in the code of editorial of D?

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

Note that we have chosen $$$x+1$$$ numbers, so by the pigeonhole principle, some two numbers will be equal modulo $$$x$$$.

Why is this true?

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

Idea for D for anyone who is a bit confused :)

The answer will always be possible due to the pigeonhole principle.

For example let’s say we have 5 vertices labeled a, b, c, d, e . We start with the 4th operation. In this case, we are looking at the vertices where the values are taken modulo 4. The possible remainders are 0, 1, 2, and 3. Since we have 5 vertices, at least one remainder must repeat (by the pigeonhole principle).

For example, if vertices a and b both have the same remainder when divided by 4, we can connect these vertices.

What if there is more than one pair of vertices with the same remainder when divided by 4? We can choose any of these pairs. It won’t affect the final answer.

Suppose we connect a and b . We can mark this component as A . Now we have 4 different components: A, c, d, and e . Next, we proceed with the 3rd operation. Using the same logic, we connect two components where vertices share the same remainder modulo 3.

Why Not Start with the First Operation? If we started from the first operation, we might encounter problems. For example, suppose we connect a and b in the first operation and then b and c in the second operation. When we reach the third operation, the remainders modulo 3 for vertices a, b, c, d, and e might be something like 0, 0, 0, 1, 2 . Now we can’t pick any pair of vertices to connect because vertices a, b, and c are already in the same component.

By starting from the (n-1) -th operation and working our way down to the first operation, we ensure that we can always find pairs of vertices to connect, gradually reducing the number of components until the graph is fully connected.

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

Has anyone solved problem D with max-flow?

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

can someone explain the segtree approach for C ?

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

C without DP: 271240394

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

I heard that this contest is hard to remark.

Anyway I didn't sign up for it :D

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

My submission 271300995 for F got TLE on testcase 81 for some reason. Anyone have any idea why?

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

I wonder why problem G is much too easy.

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

74TrAkToR never let me down :))))

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

for the first time ever the tutorial code is really clean, also F reminds me of https://cses.fi/problemset/task/2179

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

1994E - Wooden Game

You are given a forest of k rooted trees. Lumberjack Timofey wants to cut down the entire forest by applying the following operation:

Select a subtree† of any vertex of one of the trees and remove it from the tree.

Timofey loves bitwise operations, so he wants the bitwise OR of the sizes of the subtrees he removed to be maximum. Help him and find the maximum result he can obtain.


Why do I think that each operation can only remove one subtree, so it can't get all the numbers from 1 to size?

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

C is solvable in O(n) using prefix sum and 2-pointer: https://mirror.codeforces.com/contest/1994/submission/271259457

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

I have a question about problem E.Think about this test case: 2 trees with size 20 and 12,the shape of size 20 tree doesn't matter and the shape of size 12 tree look like this:

1 2 
1 3 
1 4 
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12

every other vertex is the son of vertex 1.the Editorial code gives the ans = 31,which requries to get a 8-size subtree and a 3-size subtree from the 12-size tree.I don't think it's possible to get both subtree at the same time!

Edit:oh I figured it out.First delete a vertex,then delete the whole tree will do..

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

.

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

https://mirror.codeforces.com/contest/1994/submission/271343266

This is my code for pB . I want to know where I wrote it wrong.

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

    The problem only happens when you use char array, suggested by my testings. I still don't know the cause though, if anyone knows please explain, thanks.

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

    The problem occurs when you have an array of size exactly n for an n character long string. If you change from

        scanf("%d",&n);
        char s[n], t[n];
        scanf("%s",s);
        scanf("%s",t);
    

    to

        scanf("%d",&n);
        char s[n+1], t[n+1];
        scanf("%s",s);
        scanf("%s",t);
    

    it would work fine. I believe this happens because the last character of an array of char must be '\0' or null character but I don't know the details lol.

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

Hello Codeforces I have a doubt regarding problem D. I dont understand why this Code is passing the testcases .It should give TLE right? so why it is passing the testcases and getting accepted. Any help would be appreciated. Thank you

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

can anyone prove or uphack my solution for A? i just try $$$100$$$ different permutation of $$$[1, 2, \ldots, n \times m]$$$ and it got accepted.

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

Problem D, why n=1?

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

I believe upper bound for sum in problem G is n-1, can anybody prove it formally?

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

It was a really nice contest.. I don't understand why so many downvote.. Upsolving was really fun.. Especially d, e, and g.. Thanks for such contest

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

In Editorial D , I think it must be before operation x not after operation x , there will be x+1 connectivity components in the graph .

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

CAN ANYONE TELL HOW TO APPROACH BIT MANIPULATION PROBLEMS?

is there any theory like how we should approach and all??

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

    there are certain properties of each of the bitwise operation, and bit manipulation problems requires you to implement those properties into your code. Ex: if a XOR b = c, then a XOR c = b, ...

    Just learn and solve along the way, I guess

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

For F, it's saying "If a component has an odd number of vertices with odd degree". How this is possible? Shouldn't each connected component always has even degree, since adding or removing an edge adds +2/-2 degree?

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

I didn't get the proof of D. Suppose there are two edges that can be formed with a certain x. Suppose the edges are e1 and e2; again with a value less than x we can form one edge that is either of e1 and e2, let's say e1. What if we add edge e1 first with x and then again we have the only choice to add e1. How the solution is getting optimal so that it is passing this?

One more thing... When we are merging nodes why the assignment of parent doesn't matter. Suppose a can be parent of b and b can be parent of a. Why choosing any of them is fine?

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

    The pigeonhole principle suggests that such situation cannot exist. If each of $$$x+1$$$ values are one of $$$x$$$ kinds then there must be at least one value that appears more than once. If there are $$$x+1$$$ components, you can pick any one vertex from each component and perform modulo $$$x$$$, then each value has to be one of $$$0$$$, $$$1$$$, ..., $$$x-1$$$, total of $$$x$$$ kinds, so at least one value should appear on at least two components, so you can add an edge between them.

    The merging part is nothing other than a DSU. It's a basic topic so I suggest you to search for it and learn.

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

Would F be solvable in a similar way if there wasn't the constraint that all houses can be reached using NPC only roads? I got caught up on this case for a while until I reread the constraint.

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

D is one problem that has a very brilliant solution.

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

Problem D: "Since the order of operations is not important" Could someone please explain this part?

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

E has a nice bigger friendly solution too. As said in the editorial, we can make any number from 1 till n in a tree with size n, we will try to answer greedily. It is quite clear we will definetely need the largest tree. We can remove it and add it to our answer. After that for every n, we will iterate from $$$ 1 ... n $$$ and we will get two variables $$$ x$$$ and $$$y$$$ such that $$$ x + y = n $$$. Now, we just need to maximize our answer. We can save a previous variable and then the calculation would just be

$$$ ans = max(ans, prev \big| x \big| y) $$$
code

There is also an overcomplicated implementation by actually storing all the trees in the forest and then doing subtree dp with dfs. Submission

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

In Problem E, the editorial says that if we have a bit set in sizes of two trees then we can set all other lower bits using that but this case is not possible if we can't always break the tree in desired size. For example for test case

1
2
8
1 1 1 1 1 1 1
8
1 1 1 1 1 1 1

there are two trees with size 8. but by breaking the second tree we can only obtain 1 tree of size 4 and 4 tree of size 1. Thus breaking that tree into tree of size 4 and size 2 simultaneously is not possible. So the answer for this case should be 13 (8 | 4 | 1).

Someone please correct me if i'm wrong.

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

    the answer for this case will be 15. you can remove one of the trees completely. then you can remove one leaf from second tree and then the remaining 7 nodes. total will be $$$ 8 | 1 | 7 = 15 $$$

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

For problem D, I have a seemly stupid question but I got very confused. Are the integers given distinct in the array? Or does it matter if it is not?

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

first time to see problem like D and E. i have to it's genius idea and i love it so much

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

splendid round, thanks!

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

D is cool

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

d你这就是玄学贪心呗,从大往小拿边,因为大的能拿的边小的也能拿,至于会不会出现NO情况你也不正面,别downvote啊,downvote就是急了

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

How can we make every number from 1 to the size of the tree in problem E? For example the size of a tree is 3, so how can we make 2?

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

Nice D