applepi216's blog

By applepi216, 3 weeks ago, In English

Thank you everyone for participating in the round! We hope you enjoyed the problems :)

2280A - Are They the Same?

Problem author: conqueror_of_tourist

Hint
Solution
Code

2280B - Secret String Patterns

Problem author: applepi216

Hint
Solution
Code

2279A - Reverse and Double

Problem author: conqueror_of_tourist

Hint 1
Hint 2
Solution
Code

2279B - Balanced Subsets

Problem author: conqueror_of_tourist

Hint 1
Hint 2
Solution
Code

2279C - Anti-Productive

Problem author: conqueror_of_tourist

Hint 1
Hint 2
Solution
Code

2279D - Meta Graph

Problem author: FlakeLCR

We apologize for the weak test data on this problem.

Hint 1
Hint 2
Solution
Code

2279E - Save Me!

Problem author: conqueror_of_tourist

Hint 1
Hint 2
Hint 3
Hint 4
Solution
Code

2279F - The Stones of Nim

Problem author: applepi216

Hint 1
Hint 2
Hint 3
Hint 4
Solution
Code
  • Vote: I like it
  • +39
  • Vote: I do not like it

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

Excellent tasks! But i don't liked, how simple was interactive >:(

Still orz round

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

I have a different solution to Div2C/Div1A with O(n) time.

Simply notice one of the endpoints must be at one of the indexes of the pair with the largest absolute difference, then we can do two for loops for O(n).

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

fast editorial. before the editorial of last div2 round.

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

I had a totally different solution to E, diverging when you find out how to calculate the cost given some subset that xors to $$$0$$$. We can bound the answer as $$$2 \cdot B$$$, where $$$B$$$ is the smallest subarray which is not linearly independent. Then for each subarray you can bruteforce all subsets there in $$$O(2^{\text{len} - B})$$$, and then choose the basis elements to make the entire xor $$$0$$$, and the subarray size can be at most $$$2 \cdot B$$$, giving an $$$O(n 2^{25})$$$ solution with $$$O(n)$$$ memory if implemented properly. You can do some constant optimizations / pruning on this and that makes it very fast.

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

    Ok, so I think with a similar argument my pruning makes sure that the complexity becomes $$$O(n \varphi^{25})$$$

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

    When you say you can bruteforce all subsets in $$$2^{len-B}$$$, you mean subsets of what? the elements that can themselves be written as a xor of elements of the basis? How does one such set map 1-1 to a solution that is guaranteed to include the optimal one?

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

      You loop over all subsets of the non-basis elements in the interval. Then the elements you take from the basis are forced, to make sure that the total xor is $$$0$$$. Or put another way, for a number $$$x$$$ that is in the subspace of the basis, there's a unique way to choose a subset of the basis vectors to get xor equal to $$$x$$$, and to make the total xor $$$0$$$.

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

The casework in the C editorial is unnecessary, even if we assume there is only 1 max absolute difference the algorithm will obviously find the best answer

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

orz round but i did not expect B as an interactive problem....

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

Wonderful round! Solved D with 5D dp like dp[i][k][i picked][i-1 picked][i-2 picked] and C with sparse-table :)

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

segment tree solution for a Div2 C problem?? seriously??!!

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

The samples of Div.1 D seems to be too weak, even the bfs with bugs can pass it. Meanwhile, my friend's dijkstra which doesn't initialize dis as INF can also pass it and get a WA on test 2:)

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

Intuitive proof for 1D/2F:

Consider the original graph but you start with a red token at w and a blue token at x. Then, the problem is equivalent to moving both to their target positions while performing the operations:

  • move the blue token along an edge
  • if red and blue token are on adjacent vertices, swap them

Then clearly the best path is to move the blue token next to the red token and shuffle the red token over to its target position (if it doesn't start there already), then move the blue token to its target position, meaning we only need states where the red token is already at the start or end or they are adjacent or at the same vertex

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

the code for Div2 D/ Div1 B is unnecessarily complex. A much simpler DP

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

    Can you explain it here?

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

      Recall that if $$$x \in S$$$, exactly two of $$$x+1$$$, $$$x+2$$$, and $$$x+3$$$ must also belong to $$$S$$$. Therefore, if we think of $$$S$$$ as a sequence, the difference between any two consecutive elements must be either $$$1$$$ or $$$2$$$. However, there are two more restrictions on these differences. We cannot perform the $$$+1$$$ operation three times consecutively, since this would result in four consecutive integers belonging to $$$S$$$. Similarly, we cannot perform the $$$+2$$$ operation twice consecutively, since this would result in $$$x$$$ and $$$x+2$$$ belonging to $$$S$$$, while neither $$$x+1$$$ nor $$$x+3$$$ belong to $$$S$$$.

      This motivates our DP: define $$$dp[i][j]$$$ as the number of valid sequences ending at index $$$i$$$, where $$$j$$$ represents the number of consecutive $$$+1$$$ operations that can still be performed before a $$$+2$$$ operation is forced. That counter starts at $$$2$$$. A $$$+1$$$ operation decrements the counter and cannot be performed when it is already $$$0$$$. Similarly, a $$$+2$$$ operation resets the counter to $$$2$$$ and cannot be performed when it is already $$$2$$$. From here, the transitions are simple.

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

        i did it via a state like dp[i][k][i is picked][i-1 is picked][i-2 is picked]

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

Why editorial for div2D is made so difficult to understand plus there is no mention of dp in it and then the implementation solution contains dp , Can someone explain it in simpler terms?

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

we can do binary search on answer in div1 A/div2 C

my submission

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

A brainless $$$O(m^{3/2})$$$ solution also works for D1D: 397780839

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

In D1F, could you formalize the proof that if a path exists, the application of these exchanges is actually valid?

The main issue I can't resolve is what happens when the path goes through multiple vertices belonging to the same $$$T_j$$$.

If this is what the editorial means when it is written that we should not revisit $$$T_j$$$, then it is unclear why a shortest path satisfies this.

Otherwise, it is really the crux of the proof behind the matroid algorithms (here, matroid partition), that exchanges along the shortest path are valid. Basically, this graph is a thinned out version of the intended graph for matroid partition, and I can't point out why this optimization is correct for our special(?) case.

  • »
    »
    3 weeks ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it
    • Revisiting $$$T_j$$$ is actually okay, as long as the path is a shortest path.
    • Lemma 1 seems to hold in the general case, doesn't require the matroids to be linear. That exchanging along the shortest path is valid is a consequence of the same unique matching argument cited in https://math.mit.edu/~goemans/18438F09/lec13.pdf#page=2
    • Lemma 2 does not seem to be necessary to prove the time complexity.
»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For 2279A - Reverse and Double I had a slightly different approach that runs in $$$\mathcal{O}(n \log (\max a_i))$$$ time without additional data structures:

Spoiler

My submission is here: 397754673 (a bit messy because I had no time to clean it up)

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

In problem E, where do you get the "consequence" that the optimal solution maps to that cost for a specific set from? You only proved an upper bound; in theory it could be the best solution looks very differently even if one ends up specifically xoring those said positions

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

    I was also wondering how to show a lower bound, not just an upper bound.

    Showing the lower bound for the lemma (when all a_i linearly independent)
»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Problem B. Secret String Patterns Video Editorial Solution link: https://youtu.be/KOYEFb9xwdc?si=c_bAwYeu_13eaa63

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

I have a relatively simpler solution and motivation for div2D/div1B

Main Idea
How To
Code
  • »
    »
    3 weeks ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I came up with the same idea and expected editorial solution to have just simplier DP states, but it was much, much more interesting haha.

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

Div 2 D was tuff, I had an idea we would need DP, but can anyone explain what should be the state for it? I mean what should dp[x] hold?

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

1F is just a textbook application of Edmonds’ matroid partition algorithm. Bullshit problem.

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

I love this round. Whether I'm doing a VP or playing live, Div. 2 C and D usually have a huge difficulty gap, but this round's curve was a bit gentler. I didn't get D during my VP, but the bitmask DP I had in mind for it was easy to finish after the contest, and E's threshold-enumeration idea isn't that deep either. Overall, I'm just too slow — I really enjoyed this round.

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

more clean solution on D1C

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

why there's a $$$l$$$ in the time complexity of E

if you implement a hash table, should the time complexity be $$$O(n \varphi^l)$$$

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

Nice Round but I think editorial solutions are pretty overkill, my solution for Div1A/Div2C simply involves brute force over what segment should be chosen such that one of the end points involves the pair of indices with the maximum current difference, my code is definitely messy but it's still simpler than coding a sparse or a segtree for a problem C, same with problem Div1B/Div2D, my solution is also Dp but my code is much simpler,


for(ll i = 0 ; i < n ; i++ ) {ll x; cin >> x; a.pb(x); vis[x] = 1;} for(ll x : a) { if(x == 1) continue; if(vis[x-1]) {dp1[x] = (dp2[x-1] + 1 + dp2[x-2] + vis[x-2])%MOD; ans--; } if(vis[x-2]) {dp2[x] = (dp1[x-2] + 1)%MOD; ans--;} ans +=dp1[x] + dp2[x]; ans%=MOD; }

and that's basically the whole logic, (ans initial value is all the cases involving 1 or 2 elements and the ans-- is for compensating over count) Still nice round.

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

How can I calculate the maximum adjacent element difference for a range (L, R) using prefix and suffix sums as required in 2C? I tried myself for some time with ideas like prefix[i] = rank of maximum adjacent element differences in array A[0...i] But that doesn't quite work..

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

    Let gap[i] = |a[i] - a[i+1]| and store prefix max pre[k] and suffix max suf[k] of gap. These cover everything outside the flipped segment.

    Inside the segment, one end is always next to the biggest gap, so only the other end moves. Keep a running inner = max(inner, gap[new]) as it grows.

    New max gap for segment [l, r]:

    max(pre[l-1], suf[r+1], |a[l-1] - 2*a[r]|, |2*a[l] - a[r+1]|, 2*inner)

    O(1) per segment O(n) total.

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

i do not get the dp part of 2279B — Balanced Subsets . can someone give me defination of state and transition in plain english : )

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

Thank you! This tutorial is really helpful for me!