kondasujay2's blog

By kondasujay2, history, 3 weeks ago, In English

Thank you to everyone who participated!

We are sorry for the poor testcases on C1, along with C1 and C2's solutions being so similar to the recent Div3 E.

2263A - Min Max Game

Author: kondasujay2

Tutorial
Solution
Rate the problem

2263B - Min Matrices

Author: sukon

Tutorial
Solution
Rate the problem

2263C1 - Floor of MEX (Easy Version) / 2262A1 - Floor of MEX (Easy Version)

Author: CutSandstone

Tutorial
Solution
Rate the problem

2263C2 - Floor of MEX (Hard Version) / 2262A2 - Floor of MEX (Hard Version)

Author: kondasujay2

Tutorial
Solution
Rate the problem

2263D - Culling Game / 2262B - Culling Game

Author: kondasujay2

Tutorial
Solution
Rate the problem

2263E - Traveling the World / 2262C - Traveling the World

Author: kondasujay2

Tutorial
Solution
Rate the problem

2263F - PLUSworld / 2262D - PLUSworld

Authors: sukon & kondasujay2

Tutorial
Solution
Magic
Magic Solution
Rate the problem

2262E - Paired Bracket Sequences

Author: kondasujay2

Tutorial
Solution
Rate the problem

2262F - Rank Removal

Authors: sukon & kondasujay2

Tutorial
Solution
Tutorial 2
Solution 2
Rate the problem
  • Vote: I like it
  • +104
  • Vote: I do not like it

»
3 weeks ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Auto comment: topic has been updated by kondasujay2 (previous revision, new revision, compare).

  • »
    »
    3 weeks ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    In Problem C2's official solution,

    for(int i = 1; i <= n; i++) {
           badivs.push_back({b[i] * i, (b[i] + 1) * i - 1});
        for(int j = 0; j < b[i]; j++) {
           goodivs.push_back({j * i, (j + 1) * i - 1});
        }
    }
    

    How do you know this will not give a TLE? In the sense that the worst case time complexity of this loop is n^2 right?

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by sukon (previous revision, new revision, compare).

»
3 weeks ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Nice Contest

»
3 weeks ago, hide # |
← Rev. 2  
Vote: I like it +16 Vote: I do not like it

Div1A2/Div2C2 can be solved in $$$O(n\log n)$$$ via counting sort if you store the smallest interval for each right endpoint.

  • »
    »
    3 weeks ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Remove intervals that have smaller intervals that are completely inside it and there remains O(N) intervals. I solved the DP part in O(N) using prefix sums and the only part is O(NlogN) to iterate through the initial intervals to find out for each L the smallest R of an interval starting at that L.

»
3 weeks ago, hide # |
 
Vote: I like it +20 Vote: I do not like it

For C2, my submission: 390474676. It works in O(nlogn) time comp. and O(n) space comp.

My DP: I have processed till i (0 <= i < n), and I want to find how many good sets exist with the largest element being i. Note till now, we are not considering intervals whose right endpoint is bigger that i.

For transition, I will be summing up the dp[j] such that j < i, j represents what is the second largest element of the set, and there is no interval completely inside [j + 1, i — 1]. j will form a contiguous range, so we can use prefix sum on dp values.

Thus, dp calc. part is O(n), but preprocessing intervals take O(nlogn) time.

Final answer: let pos represents the maximum left endpoint of any interval in which at least one number should lie. ans = dp[pos] + dp[pos + 1] + ... + dp[n — 1].

»
3 weeks ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

"Rate the problem" appears to have all the problems sharing the same rating votes

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by sukon (previous revision, new revision, compare).

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by sukon (previous revision, new revision, compare).

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Not a bad contest, but it was indeed tough, thx for the rating boost, but I mean it was like:

A: 800 — 900 B: 1000 — 1100 C1: 1300, maybe 1400, because I had to use Seg Tree to quickly tell me which ranges of values needed to be excluded (but it wasn't necessary because you didn't have to do updates between queries)

C2: 1700+, I read it and it seemed kinda cooked, like I don't know how to wrap my head around all the conditions that had to be satisifed -- and how to count the number of ways to satisfy all constraints.

D: 2000+, read it and realized that your favorite pupil had never seen this kind of bullshit before.

E, F: ???

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by sukon (previous revision, new revision, compare).

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

C1 is hard for me :<

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

B tricky math and realization, C1 really mathy

  • »
    »
    3 weeks ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    i found out, in min k all diagonal things, and as k decreases we move minimum non diagonal elements to the diagonal and we keep on doing till k==n, and the max k happens when it goes, n=3, 1 2 3 4 5 6 7 8 9 here k is the max, whereas 1 5 9 4 2 6 7 8 3 here k=3

    hence it is bit observation, not that much math, the only thing u gotta do is to swap mat[i][i] & mat[0][i] and you gonna get ans

»
3 weeks ago, hide # |
← Rev. 2  
Vote: I like it 0 Vote: I do not like it

in C1 and C2, i think its difference array, not prefix sum right?

»
3 weeks ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

c2 is so hard >_<

»
3 weeks ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

c2 idea seemed so oblivious , but was too much implementation that i though i was over complicating and did not try :( .

  • »
    »
    3 weeks ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Can you explain the thought process for C2 and any similar question if available

    • »
      »
      »
      3 weeks ago, hide # ^ |
      ← Rev. 2  
      Vote: I like it +1 Vote: I do not like it

      Exactly same as the editorial

      Pre- requisite idea in combinatorics:

      I have to choose a number of in the range [x,y] .

      This condition will always be satisfied if choose a value in range [x1,y1] . given x1 >= x && Y1 <= Y


      Now for each I , you mark some range as invalid . On other valid ranges you need at-least one element to satisfy MEX condition.

      The above statement is pretty oblivious if you solve C1.


      Now using the idea from combinatorics you can remove the larger interval , if a smaller one exists

      Now for each value , it will either be in a interval , or invalid , or present in no interval. (if present in no interval , you multiply the result by 2) this can be solved using DP .

      This was basically what i came up with , but looked like too much implementation which i suck at.

  • »
    »
    3 weeks ago, hide # ^ |
     
    Vote: I like it -8 Vote: I do not like it

    Exactly there is no way these many people solved C2 in Div2 without cheating. Even if you know the solution the implementation is insanely hard. Not to mention I still don't know how to make the Dp state correctly. Question D is 2x easier than this question.

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Am I the only one to solve div 1B with sqrt decomposition?

»
3 weeks ago, hide # |
← Rev. 2  
Vote: I like it 0 Vote: I do not like it

Div2 C1 has weak test cases leading to many quadratic solutions including mine getting accepted. There should be a test case where n = 10^5 and a_i = 1, 1 <= i <= n

»
3 weeks ago, hide # |
 
Vote: I like it -9 Vote: I do not like it

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

include <bits/stdc++.h>

using namespace std;

define ll long long

int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin>>t; while(t--) { int n,k; cin>>n>>k; int d=1; int re=2*n-k; int c=re+1; int count=1; int a[n][n]; if(k<n|| k>=2*n)cout<<-1<<endl; else { for( int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(i==j && count<=re) { a[i][j]=d; d++; count++;

              }
              else
              {
                  a[i][j]=c;
                  c++;
              }
              cout<<a[i][j]<<" ";

          }
          cout<<endl;
      }
  }

}
return 0;

} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ I felt B can done this way also.

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Great contest! Unfortunately, I ran out of time on E.

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

In the solution for c2 ,isn't the time complexity for getting the goodivs O(n*n) as we are already running the loop for O(n) times and while getting all the ranges of size k we are again iterating from 0 -> b[i] where 0 <= b[i] <= n.

  • »
    »
    3 weeks ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Harmonic progression :

    n + (n/2) + (n/3) + ... --> upper bound n log(n)

    • »
      »
      »
      3 weeks ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      I get it I did the same thing, but thought that inner loop is running for O(nlog(n)) times but outer is running for O(n) so overall time complexity is O(n*nlog(n)) but I was wrong. As inner loop is not running for O(nlog(n)) times for every i , instead for overall all i the the condition inside the inner loop is running for O(nlog(n))

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can anyone tell why this latest code gets passed ?? 390532511

for n=100000 and a[i]=0 for every i, it should TLE right

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

nice contest, learn a lot

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

can anyone suggest good ressources to learn more about the div2 C2 DP trick to count subset with interval conditions or other similar problems please? Thanks!

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I love this B!

»
3 weeks ago, hide # |
← Rev. 2  
Vote: I like it 0 Vote: I do not like it

I believe i have a simpler solution (implementation-wise) for D1A2: https://codeforces.me/contest/2262/submission/390455393 The idea is that you mark bad elements with difference arrays and only work with a "continuous" range of free elements (elements that can be used). In my opinion it makes calculating dp[] a bit easier

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by kondasujay2 (previous revision, new revision, compare).

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

the last part of the editorial of Div2D is preety much planless in describing the solution....the two cases if the previous champions win or not win is not described as much to understand properly....Same also for C2....Editorial should have easily understandable for all range of coders!

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I don't know where I am going wrong in C1.. https://codeforces.me/contest/2263/submission/390687639 this is my last updated solution..

»
3 weeks ago, hide # |
← Rev. 7  
Vote: I like it 0 Vote: I do not like it

I just discovered a perhaps easier alternate way to look at problem E

The problem is actually equivalent to the following:

Build the graph similarly to the editorial for E. Call indices i where a[i] < b[i] be bad indices. Let bad[i] be the ith bad index. Then, check for all i < bad.size()-1, whether it is possible to reach bad[i+1] from b[bad[i]].

This can be derived from the editorial. If bad[i] and bad[i+1] are in the same SCC, bad[i] cannot be the largest index in the SCC, and hence b[i] must also be in the SCC. We can obviously reach bad[i+1] from b[bad[i]].

If bad[i] and bad[i+1] are not in the same SCC, we can claim that the SCC that contains bad[i] is before the SCC that contains bad[i+1] in the chain (see proof below). Since bad[i+1] is in a later SCC, we must be able to visit it afterwards. Hence, the remaining walk gives a path from b[bad[i]] to bad[i+1].

Exact proof of claim: Suppose the SCC containing bad[i+1] comes first instead. Since the maximum index increases along the SCC chain(because b[i] >= i), the SCC containing bad[i] has some index larger than bad[i+1]. A path from that index down to bad[i] must cross bad[i+1], and because each node’s possible destinations form an interval with b[u] >= u, we can redirect the crossing edge to bad[i+1]. This means the later SCC can reach the earlier SCC, a contradiction.

»
2 weeks ago, hide # |
← Rev. 2  
Vote: I like it 0 Vote: I do not like it

Has anyone else directly solved the single-point modification version of D Culling Game? It probably isn't much harder than the editorial's approach. This problem is just a special case of the single-point modification version (where the single point is modified to 0).

Solved using a segment tree, with time complexity O(n log² n) and space complexity O(n).

»
2 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

In div1-C, we can actually test the b[n] value from a[2]->a[n-1].

Say m1=a[N], m2=a[i] (we let b[n]=m2)

The order should be 0 | m1 | m2 value on the left has the form k*(m1-m2), value on the right has the form k*(m2-m1) + m2.

we see that value that matches the left a[j]=k*(m1-m2) ==> a[j] can only match at most its number of divisors for m2 (so ~1000 for a[j]<=10^9). similarly for the right side ~1000 m2 that can match.

so when testing any value m2:

we can run and try to match each value, once an a[j] cannot match either left or right, we break. each value can only let at most 1k value m2 to pass it. So at most 1k * N pass can be made which make the complexity be 1k*N.

my sub: https://codeforces.me/contest/2262/submission/391009596

»
13 days ago, hide # |
 
Vote: I like it +28 Vote: I do not like it

Div1D/Div2F Simpler Solution

I tried the question post contest and was able to solve it quite easily compared to what a 2800 would require so went to editorial to verify whether this was intended or what to find out it is probably the magic solution so here is the proof:

Note: I didn't read the editorial properly since the method was completely different and much more complex so I might mention things already mentioned in the editorial.

We are given two arrays, a and b and needs to make a equal to b with two types of operation -> Operation 1 for incrementing the array by 1 and Operation 2 for traversal, and we require to start from some random node and with these two operations achieve the array equality if possible.

Claim 1: Since we only increase the element and b[i] >= i, it is always better to select the smallest index where a[i] != b[i].

Claim 2: If we are at index i and wishes to go to index j > i, we shall only go there if b[i] == j.

Case 1: It doesn't make sense to go back to i from j.

Since j > i, we can only come back to i as long as current value of a[j] <= i and it doesn't make sense to come back since a[j] < b[j] as b[j] >= j && i < j leaving a[j] unfixed and we have to go to j again from some other node to fix it and could have achieved these steps of increasing a[j] to i that time as well making the operation not profitable.

Case 2: It doesn't make sense to go back to i from k < j. Same reason as above, still a[j] < b[j] as b[j] >= j && k < j and still have to fix j as well as k from some other node.

Case 3: It doesn't make sense to go back to i from k > j.

Assuming Claim-2 holds, k = b[j], in this case, we can only go back to i if a[k] <= i, it that case firstly k is not done and must be reachable from some other node to fix it, secondly if a[k] <= i then a[k] < j, this node could have been used to fix up j and didn't require j to be fixed by going there from i and if k can only be reached from j, then atleast either i or k must be left unfixed making the ans not possible.

Since we covered all 3 cases, the claim must hold.

Claim 3: If some j < i is unfixed and we can reach j from i, we shall go there to fix it.

Reason: From claim-2, if we go to j, we must fix it completely before going to any k > j. If doing so leaves i as unfixed, not going to j would have left j as unfixed as if we can go to j from some other node v, we could also reach i and v > i since we reached v by not going to any node less than i from it, we could have fixed j from i itself and used v to go back to i. Incase visiting v is not possible if we go to j, then going to j from v to fix it will leave v unfixed and again not solve anything.

Claim 4: When b[i] == i, the traversal ends.

It can be proved that for a valid solution to exist the four claims will also give a valid solution though i might not have articulated the claim 3 well but basically proving that going to j < i from i to fix j would not lead to ans if ans exist would lead to contradiction.

From these four claims, we can simulate the enitre way Bessie should traverse to make the two arrays equal. It shall be noted the claims at no point states anything regarding if it is possible to actually make the two arrays equal, it only states a valid path if the solution exists. So if on traversing based on these claims, at the end leads to a != b, then the no traversal shall lead to a == b and ans doesn't exist.

The proof for no traversal to exist is not explicitly written but on finding one would lead to solution when the claims failed to do so would again lead to contradiction. The first claim tells the start point, fourth claim the end point while second denotes forward traversal and third denotes back traversal.

We can direstly simulate this code and update a accordingly and when the traversal ends check if a == b to find out if it is possible or not.

Start node chosen by Claim 1. Lets say current node is cur initally equal to start node.

  1. If a[cur] > b[cur] -> It is not possible to make then equal.

  2. If a[cur] == b[cur]

    a. If a[cur] == cur -> Claim 4 states traversal ends

    b. Else Claim 2 -> cur = a[cur] with Operation-2

  3. a. If a[cur] is not fixed -> Claim 3 -> cur = a[cur] with Operation-2

b. Since a[cur] is fixed, no need to go there so just increase a[i] = a[i]+1 with Operation-1.

Implementation: 391363278

»
11 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Authors please share the idea for dp solutions as well instead of just writing a one liner, C2 isn't that straight forward. Also, please write the hints instead of directly giving the tutorial.

»
10 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

i have best solution for problem B:

391083236

no memory used, simple to look at and easy to understand