Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. Оно применяется начиная с раунда 972. ×

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

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

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

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

Разбор
Код

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

Разбор
Код

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

Разбор
Код

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

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

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

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

1994F - Stardew Valley

Разбор
Код

1994G - Minecraft

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

1994H - Fortnite

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

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

D is a cute problem

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

What is E?

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

Why are people down voting?

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

Editorial is so fast.Thank You!

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

CDE are very nice

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

the editorial came faster than my girlfriend

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

thank you for fast editorial

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

Think of the most stupid solution you can do

Great editorial for problem G

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

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

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

      Cant identify exact mistake in code but for input

      1
      6 16
      1 13 12 8 6 10 
      
      

      correct output is $$$15$$$, your code prints $$$14$$$ instead.

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

    Bro please share your approach Thank you bro

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

    can you please explain how?

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

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

      How will the next index $$$k$$$ when $$$g$$$ will hit $$$0$$$ be $$$l_{l_i +1}$$$?
      edit: got it
      edit q: how this works? wont the time complexity be $$$O(n^2)$$$?

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

        No, we will go through array $$$a$$$ exactly twice while calculating $$$l$$$ because we know $$$l_i<l_{i+1}$$$ so there is no need to go back to calculate each $$$l_i$$$.

        Time complexity for that part will be $$$O(2n)$$$ which is $$$O(n)$$$.

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

        can you explain how you got it lli+1 ?

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

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

      Unfortunately that won't work, try to find another solution.

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

      Wait I didn't fully understand your solution can you explain it little more?

      Because it looks like $$$O(n^2)$$$ complexity.

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

        i was writing the soln,but during typing I got what was wrong,thanks!!

        by the way i wanted one tip.

        i am able to solve problem up to 1100 rating outside contest.but in the contest idk why I cant solve.

        and also I take much time I think,is there any way to upgrade my skill and speed

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

          Solving problem in practice and in contest is same so don't think about rating or points while in the contest.

          And only way to improve skill and speed is by practicing I guess.

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

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

    no

    010000 -> 011111 l = 2, r = 6

    011111 -> 001111 l = 1, r = 2

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

    s = 010000; l = 5, r = 6 => s = 010001; l = 4, r = 5 => s = 010011; l = 3, r = 4 => s = 010111; l = 2, r = 3 => s = 011111; l = 1, r = 2 => s = 001111 = t. The answer is "YES". i = 2 — the position of the first '1' in s, and there are only '0' in the interval [1, i) in t, so, according to given solution the answer is also "YES".

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

      one question, why do we need to do this operation in the reversal order(starting with an end)?

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

        We don't need, we can do l = 2, r = 3, ..., l = 5, r = 6, and then, l = 1, r = 2.

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

          thank you) cause in the editorial, there was written — "acting from the end"

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

    The answer would be "YES". Note that "NO" would be the answer iff there is a '1' in t and '0' in s, and the count of '1' in s before this index is 0.

    E.g. 
    s = 00100
    t = 01000
    

    It is to be noted if '1' appears in s before a particular index, all the elements after the index can be made either '0' or '1'. Self xor is allowed, and thus, we can make any element that's '1' to 0.

    In the above example, at index = 1, it's impossible to make '0' to '1' (to match the strings).

    Here is my solution, you can have a look: 271233150

»
2 месяца назад, # |
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.

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

    this problem is too troll, if it's placed as C i think i can prolly solve it in 10 min lol

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

    hey can you share some resources to study for bitwise operation. I always find it difficult whenever i have to deal with these types of question

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

    after solving it today, i also agree with you. the idea isn't that complicated

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

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

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

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

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

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

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

Thanks for fast editorial!

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

Any Minecraft players :D

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

Easier sol for A: 271203621

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

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

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

    you have to dp some way or the other

  • »
    »
    2 месяца назад, # ^ |
      Проголосовать: нравится 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;
    }
    
»
2 месяца назад, # |
  Проголосовать: нравится +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."

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

Thank you for fast editorial!

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

D was a really cool problem. orz

»
2 месяца назад, # |
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.

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

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

  • »
    »
    2 месяца назад, # ^ |
    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.

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

    as size of the array and arr[i] both are up to 1e6, then how can we say that it won't give TLE ??

    Is there any proof for this??

    Please share it will he helpful

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

      The sum of all tree sizes (k and n) is up to 1e6 over all testcases, so in total you will have at most 1e6 decrements.

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

    sorting in not required

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

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

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

    mod is m that we need to find

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

      Then I don't get how querying any string with non-modulus hash in $$$[h_1-a_1-m, h_1-a_1-1]$$$ is enough to find $$$m$$$. Suppose $$$h_1=10^{15}$$$, $$$a_1=0$$$, $$$m=1000$$$ and we ask about some string with real hash equal to $$$999999999999050$$$ and get $$$50$$$ as answer. How can we know that $$$m=1000$$$? It could also be equal to $$$100$$$ for example.

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

        We know that $$$h_2 \ge h_1 - a_1 - m$$$($$$h_2$$$ is hash of found string), so $$$m$$$ can't be $$$100$$$. $$$m = (h_1 - a_1) - (h_2 - a_2)$$$, where $$$a_2$$$ is $$$h_2$$$ $$$mod$$$ $$$m$$$.

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

        if m=100 in this case 999999999999050<h1-a1-m

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

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

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

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

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

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

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

    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

    how can we prove this ?

    upd: Resolved

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

    Thanks for explanation :)

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

    Great explanation!

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

    way better explanation than the editorial

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

    Thanks for your explanation, it makes far more sense to me than the editorial one.

    But still I have 2 doubts:

    1. "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." -> Why??

    2. "Now we can’t pick any pair of vertices to connect because vertices a, b, and c are already in the same component." -> why can't such case happen when operations are performed in reverse order?

    update: understood by doing dry run in both order.

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

    Thank you so much

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

    I have also used same logic..

    Simpler implementation: MY SUBMISSION LINK

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

why does this code fail for C

    int n, x;
    cin >> n >> x;
    take(a, n);
    vector<int> dp(n + 1, 0);
    for (int i = 1; i <= n; i++)
    {
        dp[i] += dp[i - 1] + a[i - 1];
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        if (a[i - 1] > x)
            continue;
        int prev = lower_bound(all(dp), dp[i] - x) - dp.begin();
        int prevprev = lower_bound(all(dp), dp[i - 1] - x) - dp.begin();
        ans += (i - prev) + (prevprev);
    }   
    cout << ans << endl;
»
2 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Has anyone solved problem D with max-flow?

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

    I’ve tried, but it seems to be wrong.I can’t guarantee that the graph is connected.The graph I make may contain loops.

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

can someone explain the segtree approach for C ?

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

C without DP: 271240394

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

    why the loop runs from n-1 and not from start?

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

      reason 1. for any loop dp[i] =function(dp[j],dp[j2],dp[j3].....)

      then if all j's are less than i then we have to calculate lesser dp values for lesser i's first in order to do above calculations correctly,so we have to calulate all dp's looping from i=small vale to i=maxvalue

      similarly if all j's are greater than this i then we do looping in decreasing order

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

    Can you pls explain your solution? Thanks.

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

I heard that this contest is hard to remark.

Anyway I didn't sign up for it :D

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

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

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

I wonder why problem G is much too easy.

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

74TrAkToR never let me down :))))

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

    In all, being 74 rounds means higher chance of being sponsored but higher chance of low quality.

    Better quality of problems — higher chance of Global

    That is really laughing.

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

Wait... D has no answer '-1'?

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

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

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

The simple solution for problem A is to increase every element by one and n*m integer change into 1.

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

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

    Start deleting from the leaf nodes one by one . Then as soon as you get the required size, you can delete the entire tree.

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

During contest in Last 15 minutes site stops working after robot verification starts that causes not able to submit solution have writtens.

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

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

»
2 месяца назад, # |
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..

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

.

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

https://codeforces.net/contest/1994/submission/271343266

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

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

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

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

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

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

    I didn't prove, but except for the obvious $$$n=m=1$$$ case it seems like the worst chance for a random permutation to satisfy it is $$$1 \over 3$$$ when $$$n \times m=3$$$, so the chance of not finding an answer with 100 tries is $$$~2.46 \times 10^{-18}$$$. Even if we try hacking it $$$10^9$$$ times it will still almost surely pass.

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

Problem D, why n=1?

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

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

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

submitted code for a 959 A diverse game getting failed testcase on vscode and output is wrong but here it got accepted.how so???

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

»
2 месяца назад, # |
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 .

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

CAN ANYONE TELL HOW TO APPROACH BIT MANIPULATION PROBLEMS?

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

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

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

      by the way i wanted one tip.

      i am able to solve problem up to 1100 rating outside contest.but in the contest idk why I cant solve.

      and also I take much time I think,is there any way to upgrade my skill and speed

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

can someone tell me whats wrong with the code , i have tried to read the editorial of the G question and replicated the same , but it exceeds time limit.

ll m=1000000000+7;

string m1;
ll k;
vector<vector<int>> arr;
vector<ll> crr;
ll n;

bool rec(ll i,ll sum){
    if(sum<0){
        return false;
    }
    if(i==k){
        if(sum==0){
            return true;
        }else{
            return false;
        }
    }
    ll c1=crr[i];
    if(rec(i+1,sum-((n-c1)*(1ll<<i)))){
        m1+='1';
        return true;
    }else if(rec(i+1,sum-((c1)*(1ll<<i)))){
        m1+='0';
        return true;
    }else{
        return false;
    }
}

ll solve()
{
    I n>>k;
    int brr[k];
    string s1;
    I s1;
    for(int j=0;j<k;j++){
        brr[j]=(s1[s1.size()-j-1]-'0');
    }
    for(int i=0;i<n;i++){
        string s;
        I s;
        vector<int> V;
        for(int j=0;j<k;j++){
            V.push_back(s[s.size()-j-1]-'0');
        }
        arr.push_back(V);
    }
    for(int i=0;i<k;i++){
        ll c1=0;
        for(int j=0;j<n;j++){
            if(arr[j][i]==1){
                c1++;
            }
        }
        crr.push_back(c1);
    }
    ll sum=0;
    for(int i=0;i<k;i++){
        if(brr[i]==1){
            sum+=(1<<i);
        }
    }
    // for(int i=0;i<n;i++){
    //     for(int j=0;j<k;j++){
    //         O arr[i][j]<<" ";
    //     }
    //     O endl;
    // }
    if(rec(0,sum)){
        O m1<<endl;
    }else{
        O -1<<endl;
    }
    return 1;
}

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        solve();
        arr.clear();
        crr.clear();
        m1="";
    }
    return 0;
}- 
Your code here...
»
2 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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.

»
2 месяца назад, # |
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?

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

    nvm, i got it, it's the vertex with odd degree not the whole connected component.

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

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

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

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

D is one problem that has a very brilliant solution.

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

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

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

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

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

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

The easiest approach for Problem-A is:

To transverse to each and every element of matrix A and decrement it by 1 i.e. A[i][j] -= 1. then find zero and replace it with n*m. AND report the following matrix as B.

271203176

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

I have made a video explaining the problem C. Hungry Games. Do check it out at:

https://www.youtube.com/watch?v=_FMUfMAVVVw

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

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

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

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

splendid round, thanks!

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

For E the statement “we can make every number from 1 to the size of the tree” of editorial is not correct as some even numbers cannot be made because of or with 1.

correct me if Im wrong.

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

D is cool