Evirir's blog

By Evirir, 6 weeks ago, In English

2049A - MEX Destruction

Idea & preparation: Evirir

Tutorial
Solution

2049B - pspspsps

Idea & preparation: Evirir

Tutorial
Solution

2049C - MEX Cycle

Idea and solution: Evirir and Kaey
Preparation: Evirir

Tutorial
Solution

2049D - Shift + Esc

Idea: Evirir and Kaey
Solution: CSQ31, Evirir, Kaey
Preparation: Evirir and CSQ31

Tutorial
Solution

2049E - Broken Queries

Idea & preparation: Evirir
Solution: Kaey

Tutorial
Solution

2049F - MEX OR Mania

Idea & preparation: YouKn0wWho

Tutorial
Solution
  • Vote: I like it
  • +89
  • Vote: I do not like it

»
5 weeks ago, # |
  Vote: I like it +29 Vote: I do not like it

first.

B was brutal

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

    I overcomplicated it and am crying now.

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

    i spent so long missing a case for my B solution lmao

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

    I haven't participated but thought b was easy bro?

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

    C is also awful in my opinion.

    • »
      »
      »
      5 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      jocker

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

second.

E was interesting.

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

B broke my back

»
5 weeks ago, # |
Rev. 2   Vote: I like it +13 Vote: I do not like it

Third.

I will quit competitive programming...

»
5 weeks ago, # |
  Vote: I like it +23 Vote: I do not like it

b was absolute shit

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

I didn't really learn anything from this round. B was either brute forced implementation(like i did) or editorial's edge case heavy direct implementation, C was just observations derived by dry running mutliple cases. Yesterday's global round had a better C.

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

    There was a simple logic in B, can we fit a certain set of number which has to be smaller than the gap between last s and first p!

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

    You can check my submission for a simple implementation !

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

    Check my submission for an elegant approach to B

»
5 weeks ago, # |
  Vote: I like it +26 Vote: I do not like it

For F, my solution does actually do the updates in the normal order. I maintained for each power $$$k$$$ a set of ranges, where each range stores a frequency array of size $$$2^k$$$, as well as a multiset of the lengths of valid ranges (to get the answer). A range is valid if every element in its frequency array is nonzero.

Then each update either modifies or splits $$$\text{log} \, n$$$ ranges. For each power $$$k$$$, find the range that position $$$i$$$ is contained in (or skip if it doesn't exist). If $$$a_i + x$$$ is still within the range, just update its frequency array. Otherwise we need to split it into two ranges. We can use "large-to-small splitting": modify the frequency array of the larger half, then make a new range for the smaller half (if its size is at least $$$2^k$$$). So the total number of frequency array updates per power $$$k$$$ is at most $$$O(q + n \, \text{log} \, n)$$$, so the overall complexity is $$$O((n + q) \, \text{log}^2 \, n)$$$.

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

I use bfs in problem C.I thought I would get MLE or TLE pending but I passed the testings.:)

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

    How?? I didn't think of it. Can you explain your approach a little?

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

      I solved it using dfs but I think the idea should be pretty much the same. First, I make a graph where the edges connect friends. Then, I run dfs and every time some vertex is visited, I set its value to the mex of already visited neighbors. It works because I never break the condition for the vertices that were already set

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

      very similar. For each node u,if it is not the mex of neighbors, I set its value to the mex. If it is,I set the unassigned neighbors as mex+1.

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

ahh B...

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

got d right after the contest ended

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

IMO D would've fit it's position better if time limits would've cut $$$O(n*m^3)$$$ solutions! Or maybe I'm just salty that I spent way too long finding the $$$O(n*m^2)$$$ solution XD

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

    the n ^ 4 and n ^ 3 are the exact same , just maintain an array of minimums for each column at each row i didnt even realize my code was n ^ 4 submitted 2 times before realizing and adding that vector was enuogh

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

      I think you misunderstood me, some $$$O(n*m^3)$$$ solutions passed : 297536216 .

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

        Wait!!! How is it possible? 5 * 10^4 *(200 * 200) is around 2e9 iterations. How the solution is getting accepted?

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

        i had a similar solution , O(n * m^3) but mine TLEd on tc5. i could not figure out why.

        submission : 297577834

        it passes in 3.3s when i tried to submit it in a mashup gym.

        still , how could i make it pass?

        (also i take inf = 1e15)

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

          nvm, wrote iterative dp and it works just fine in under 1s. yayy

          submission: 297581320

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

            Never had it crossed my mind to put the absolute full path in the include directive. That's cursed af.

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

              haha , cursed but works! i was not able to figure alternatives with my IDE so i thought to leave it be ,why should it matter.

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

    wait... $$$O(n*m^3)$$$ actually works?... you're right, limits cutting those solutions would've been nice.

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

The limit of $$$33$$$ queries (instead of $$$32$$$) is to allow less optimized solutions and other solutions.

This is brutally cruel, I got WA because my max query count was $$$34$$$... Why is there the need to outright destroying implementation that simply lacks a bit of thinking that isn't much crucial to the problem idea?

(Of course, I am a bit salty, and I don't think I should really blame it coz I upsolved either way, but I feel the "less optimized solutions to pass" intention is quite not-so-there.)

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

    while(l <= r) is a very dangerous way of binary searching because in the most common way u dont make full use of the info u get after each query , using every bit of info u had , u could've passed it just with 29 queries which u had

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

      So you are telling me that I could only be unoptimal in at most $$$1$$$ place out of $$$2$$$... :,)

      Btw, I'm curious on the binsearch implementation. How could this be made use better? I usually code that way coz' it's the most mathematically coherent algorithm in my head.

      • »
        »
        »
        »
        5 weeks ago, # ^ |
        Rev. 2   Vote: I like it 0 Vote: I do not like it

        i remember a problem called ruler or something from a div 4 not sure if i can find it , it showed me how dogshit this way of binary searching is , still doing it because i dont have to worry about the floor or ceil of the middle point

        edit : problem 1999G1 - Ruler (easy version)

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

          ...I ternary searched that problem, and with tersearch I had a completely different setup...

          Still I think I kinda understand what you're getting at here...

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

        My binary search is like this

        	l, r, res := 2, n/2, 0
        	if !kinlow {
        		l, r = (n/2)+1, n-1
        	}
        	for l <= r {
        		mid := (l + r) / 2
        		if feasible(mid) {
        			res, r = mid, mid-1
        		} else {
        			l = mid + 1
        		}
        	}
        
  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    btw, your exact same WA code passes if you change x4 = 1^x1^x2^x3

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

      Yeah, I did something similar to that already. It's not hard to figure but it's just babbling to be squeezed sometimes...

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

B made me want to KMS.

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

I think this is even more difficult than before

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

I dislike C so much, how did people come up with the solution?

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

    i thought C was nice lol

    my solution was a bit diff, basically I set $$$a_x=0$$$ and $$$a_y=1$$$, then filled in everything between

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

    in such problems thinking about a few specific cases and then generalizing helps a lot.

    look at the graph formed by the numbers, and first look at the cases when x and y are already friends :

    Case 1: N is odd the smallest case is a cycle of 3. it's easy to see 0-1-2 works. can you generalise this?

    if I were to add 2 nodes between 0 1, it would be 1 and 0 giving us a solution for N= 5. you could extend this for all odd N

    Case 2: N is even the smallest case is a cycle of 4. here 0-1-0-1 works! if I were to add 2 nodes between 0 and 1 it would be 1 and 0.

    with this you've generalised the solution for even N

    now what's left is cases where x and y aren't already friends

    here you can have an odd cycle next to an even cycle, two even cycles, or two odd cycles. like above starting with cycles of length (3,4) , (3,3) ,(4,4) and then generalising it helps you see the construction.

    297495561

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it -9 Vote: I do not like it

    C was, without a doubt, the most utterly repulsive problem I'd ever had the misfortune of encountering.

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

very cool contest

tho the difficulty had a very sudden jump on e while maintaining a steady grow from a to d (in my opinion, of course)

»
5 weeks ago, # |
  Vote: I like it +35 Vote: I do not like it

Where is the cycle in the DP transition for D coming from? Surely you can just do $$$g(i, j, x) = \text{min}(g(i, j - 1, x), f(i - 1, j) + kx) + a(i, j + x)$$$, and there is no cycle?

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

    That was also my solution and it passed. Probably the authors just overcomplicated things

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

    is the recurrence given in the editorial even correct ?

  • »
    »
    5 weeks ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    Yes you are right, I got the cycle part mixed up with another solution. (the editorial is updated)

    • »
      »
      »
      5 weeks ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      The recurrence in the editorial is still incorrect , the $$$kx$$$ term should be with the $$$f(i-1,j)$$$ portion only

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

    I am confused. What about $$$g(i,0,x)$$$ depending upon $$$g(i,m-1,x)$$$? Why shouldn't there be a cyclic dependency?

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

      It doesn't. You can only move down or right, you can't wrap around the grid yourself (only the rows cyclically shift). So the only way to get to cell $$$(i, 0)$$$ is from cell $$$(i - 1, 0)$$$, and so $$$g(i, 0, x)$$$ depends only on $$$f(i - 1, 0)$$$.

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

I was one +-1 away from solving E during the contest... Cool problem though

»
5 weeks ago, # |
  Vote: I like it +4 Vote: I do not like it

Editorial for B made me pity meself.

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

    Maybe you over-complicated B during the contest and panicked maybe? Few things were obvious like if there is no 'p' or no 's' then ans is obvio 'YES', and if 'p' came before 's' then it's impossible also trivial if we just made the subarray and saw as mentioned in q. The next thing i did was make few cases like 'sspp' etc and checked where i came up with 'YES' is only possible when we have 'sppp..' or 'ssss..p' type of string rest it won't be possible. Usually i am too dumb for qs but maybe yesterday was just lucky day for me.

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

      Great observation Lve. You weren't lucky , you are improving. Also , that's alot of maybes to put irl , had had a hard time dealing with my maybes so i prefer to say i sucked.

»
5 weeks ago, # |
Rev. 4   Vote: I like it +45 Vote: I do not like it

for F you can solve in $$$O(n \log n)$$$ as follows. Observe that when checking for $$$2^k$$$, only sets with size at least $$$2^k$$$ can possibly work, so delay building them until the size is $$$2^k$$$. With this, it is reasonable to use just an array of size 2^k to store the frequecny array. Insetad of merging two sets in time $$$set constnat * min(|A|,|B|)$$$, we can merge this in exactly $$$2^k$$$. A simple amortization will show that this process is $$$O(n)$$$ for each target power of two. So this part works in $$$O(n log n)$$$.

We also have to maintain the maxmium size of all working sets. This costs $$$O(X log X)$$$ for $$$X$$$ at most the number of built set, with the log from constnats of map. Notice that when checking for $$$2^k$$$, $$$X$$$ is bounded by $$$\frac{n}{2^k}$$$. Suming this over $$$k$$$, this part is also $$$O(n \log n)$$$.

Edit: I forgot that we you process queries, the same already built set can be moved in/out of working sets, so unfortunately the last seemingly easiest part is actually the slowest at $$$O(n log^2 n)$$$ I don’t see a good way to save the log in this task.

Second edit: it turns out saving this last log isn’t as bad as I thought. It is not a true savings, but vEB tree (rather, the practical base 64 variant) allows this final part to be done in O(n log n log log n) overall

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

Alternative solution to C and D.

C: If $$$(x>y)$$$ swap $$$(x,y)$$$, set $$$A_x = 0$$$, and alternate between 0 and 1 and wrap that around on the right side until $$$y$$$ (not including $$$y$$$). Also do the same for the left side. Then $$$A_y = max(A_{y-1},A_{y+1}) +1$$$. This works because $$$A_y >=1$$$ because $$$y$$$ connected to $$$x$$$ and $$$A_x = 0$$$.

D: Very similar to the editorial, but I set up the dp differently.

Let $$$dp[i][j][b] =$$$ the minimum cost using to get to $$$(i,j)$$$ shifting the $$$i$$$th row $$$b$$$ times.

Let $$$stored[i][j] =$$$ the minimum cost to get to $$$(i,j)$$$ including operation costs and across all possible shifts.

Intitally, $$$dp[i][j][b] = inf$$$, for all $$$(i,j)$$$. Except $$$dp[0][j] = arr[0][j]$$$.

Transitions are as follows:

$$$dp[i][j][b] = min(dp[i][j-1][b] + arr[i][j],stored[i-1][j] + arr[i][j])$$$

$$$stored[i][j] = max(dp[i][j][b] + b*k)$$$ for all $$$b$$$ from $$$(0,m)$$$

»
5 weeks ago, # |
Rev. 2   Vote: I like it +6 Vote: I do not like it

I did the following DP in D:

  1. dp[i][j] — mincost of getting to cell (i,j).

  2. dp[i][j] = min_{t <= j} dp[i-1][t] + f[t][j], where f[t][j] — mincost of getting from (i,t) to (i,j).

  3. computing f is the hard part: I compute all f[l][l+len-1] for each given len=1..m.

First, I pushed b[i][l+len-1] - b[i][l-1] + k * (l-1) to a queue with minimum for all l = 1..m. In the queue for each l, I support values of all m cyclic shifts of the row i. Then f[l][l+len-1] for each l = 1..m-len+1 is f[l][l+len-1] = (min of the queue) - k * (l-1). f[l][r] for each row i is calculated in O(m log m), and dp[i][j] is calculated in O(m) for each (i,j), so the total complexity is O(nm^2 log m).

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

    An interesting approach to finding cheapest paths on a "layer" in a matrix!

    I found it in a different way, for each length len do: (assuming that i fixed)

    1. Calculated all sum's (from each start position j) of length len: $$$\sum_{k=j}^{j+\text{len}-1} a_{i,k}$$$

    2. When found minimal of them — let it be for position $$$j = \text{pos}$$$. Then cheapest passing from $$$(i, \text{pos})$$$ to $$$(i, \text{pos}+\text{len}-1)$$$ is the path without a shifting (just $$$a_{i,\text{pos}} + a_{i, \text{pos}+1} + .. + a_{i, \text{pos}+\text{len} - 1}$$$)

    3. Next moving from pos to the left, choose cheapest path from:

      • path without a shift: $$$\sum\limits_{t=j}^{j+\text{len}-1} a_{i,j}$$$
      • path shifted "by one" (started from $$$j+1$$$): $$$\sum\limits_{t=j+1}^{j+1+\text{len}-1} a_{i,j} + k$$$

    My submission: 299116684. Total complexity: $$$O(nm^2)$$$, but in this solution getting lost generality, because it used the fact of a linear penalty for shifting.

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

Note that you can do binary search directly on $$$[n/4+1,n-1]$$$ in E. Code:297545783.

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

Nice contest... I'm happy with my performance, finally reached specialist!

I don't understand why my dp solution for D did not work, it is failing on 2 of the sample inputs. Can someone please point out where I'm going wrong here? (Assuming I'd have optimized the transition to make it O(nm^2) by saving the min values for each row)

My Code
»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

I could have submitted B if I had only 5 more seconds, hurts lol

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

C took 10% of time as compared to B.

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

For C i just keep iterating over answer untill it converged, i did this coz i thought it will converged in ~ 4 steps but not sure exactly how.

can somebody hack my solution? or help me to prove why this works? 297490012

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

    coz i thought it will converged in ~ 4 steps

    Yeah. The thought train is simple: friends should not have equal values, so answer should be at most $$$\text{cnt}_{\text{friends}}$$$. And since you can only have at most $$$3$$$ friends (two adjacent, one predetermined in $$$(x, y)$$$), so...

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

B makes me feel like I am dumb:⁠-⁠*

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

I am going back to noobie

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

-121 :D

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

Nice B
Could anyone suggest similar problems or tell me what topic this falls under? Any tips to solve these types of problems faster?

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

    B provides so many cases. When they provide so many, you know you have to look at them. And then you should do a bit of reasoning, which is, really easy I think.

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

    It was greedy no others concepts is also required.

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

This contest was more inclined towards implementation.Though, I became specialist thanks to this contest.

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

for D the second same for is unnecessary and also there is no path from [i][m — 1] to [i][1] so there is no need to write tmp[(j+m-1)%m]

so simpler code is:

for(int i=1;i<=n;i++){
    for(int shift = 0;shift<m;shift++){
        vector<ll>tmp(m,1e18);
        for(int j=0;j<m;j++)tmp[j] = dp[i-1][j] + a[i][(j+shift)%m] + k*1LL*shift;

        for(int j=1;j<m;j++)tmp[j] = min(tmp[j],tmp[(j-1)%m] + a[i][(j+shift)%m]);
        for(int j=0;j<m;j++)dp[i][j] = min(dp[i][j],tmp[j]);
    }
}

(100% correct)

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

    also tmp[(j-1)%m] can be changed to tmp[j-1](more clear...)

  • »
    »
    4 weeks ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    Why is there no path from [m-1] to [1]? For eg about the case where we shift $$$i$$$ th row to the left m-1 times. then [i][1] is to the right of [i][m-1].

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

      I think you misunderstood, we can move only to the down or right and thats not about shifts : we already know how many shifts we did and tmp[i] is the ith row AFTER shifts. so we can simply write : tmp[j] = min(tmp[j],tmp[j-1] + a[i][(j+shift)%m]) (if you still did not understand, proof is -> code, you can submit it)

»
5 weeks ago, # |
  Vote: I like it -6 Vote: I do not like it

$$$B$$$ $$$\gt$$$ $$$D$$$

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

Codeforces Hot News!

Wow! Coder chenlinxuan0226 competed in Codeforces Round 994 (Div. 2) and gained -160 rating points taking place 4892

Share it!

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

Codeforces Hot News!

Wow! Coder chenlinxuan0226 competed in Codeforces Round 994 (Div. 2) and gained -160 rating points taking place 4892

Share it!

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

My 4th contest and Div 2 gives me real reality chevk. Solved only A ... and crossed 1000 barrier yay! 2025 will be a year of CP for me.:)

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

For B, we just need to check if array [1,2,3...,n-1,n] or [n,n-1,...,2,1] satisfies the condition. So we don't have to worry about corner cases

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

Just being curious, what problem B and C teaches us?

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

for problem B, my thought process is segments that need to form permutations must be in subset relation. otherwise there is an element in the smaller segment that is not in the larger segment. then the larger segment is not a permutation.

hence all segments should form a chain of subset. to check this, intersect all the segments and check if it is one of the segment.

submission

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

since a is not the entire p, a does not contain pn. However, b contains pn. In Editorial for problem B can anyone explain how this contradiction is happening? As per my understanding of this line if b contains pn what is problem b may be larger so that b contains some extra elements that a does not have.

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

This comments section is satisfying. I thought I was the only one struggling in b lol.

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

In the MEX cycle problem what i did was, i maintained the friends of each element, and then i started iterating from 1..n, and iteratively assigning MEX by looking at their friends, for the MEX answer array i maintained -1 initially for all the values, during the iteration if the friend's value of any element came out to be -1, i just took the element itself, and if the friend's value was not -1 (which will be in the case where i must have calculated the friend's MEX before) i just used its MEX value which i updated in answer array. This approach works but only if i loop from 1..n, if i choose any other order, or iterate in reverse, this fails for some cases, thats why there is a confusion. If any one gets whats happening here please reply to me.

Submission --> 297573068

int find_mex(set<int> values)
{
    int mex = 0;
    int n = values.size();
 
    fore(e, values)
    {
        if (mex != e)
            return mex;
        mex++;
    }
 
    return mex;
}
 
void solve()
{
    int n, x, y;
    cin >> n >> x >> y;
 
    vi a(n + 1, -1);
    vvi adj(n + 1);
 
    rep(i, 1, n + 1)
    {
        set<int> s;
        int left = (i == 1) ? n : i - 1;
        int right = (i == n) ? 1 : i + 1;
        s.insert(left);
        s.insert(right);
 
        if (i == x)
            s.insert(y);
        else if (i == y)
            s.insert(x);
 
        for (auto val : s)
        {
            adj[i].pb(val);
        }
    }
 
    rep(i, 1, n + 1)
    {
        set<int> values;
        fore(e, adj[i])
        {
            if (a[e] != -1)
                values.insert(a[e]);
            else
                values.insert(e);
        }
 
        a[i] = find_mex(values);
    }
 
    for (int i = 1; i <= n; ++i)
    {
        cout << a[i] << " ";
    }
    cout << endl;
}
»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Submission ---> 297522704

For the B question, what i did was, i normally iterated through the string and if i see an 's', i push a pair {i, n-1} in a vector, and if i see a 'p', i push {0, n-1} into the vector, and at the end, I iterate across the vector and i check if either the first element of all the pairs is 0, or the last element of all the pairs is n-1, then the answer is "YES", otherwise "NO".

This way there is no need to handle EDGE CASES as we will just be checking if the permutations either end at same index, or start from same index, in all other cases it will be a "NO".

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

In problem D, why do you substract (*) to the transition? Is it a substraction or just to explain it later?

Also, I don't get why "the g(i,j−1,k) term is from the case where you move from (i,j−1) to (i,j)", shouldn't it be g(i,j−1,x)?

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

    The (*) part is edited, it's supposed to be a marker for the equation

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

This B made me cry

»
5 weeks ago, # |
  Vote: I like it -7 Vote: I do not like it

Author of B must get death penalty for such shit crime

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

Kudos to the authors of this round, I really liked the problems!

My intuition for B was the following: - create a vector of the required left,right indexes between which there must be a permutation, and sort them by the size of the permutation - then take them one by one: our first permutation will be the first one in the list, and from the second one onwards, we check the condition: if the new permutation we want to write has its borders outside of what we already are assuming is a permutation, then we extend our permutation to cover this new area - otherwise, this new permutation partially overlaps with our current one, but also partially doesn't, and we run into an incompatibility, meaning it the construction of the final permutation is impossible

(Sorry if my thought process isn't understandable, English isn't my native language.)

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

Why In Problem E. "Make 2 queries [1,n/4] and [n/4+1,n/2]. This tells us which half the 1 is in: it is in [1,n/2] if the query results are different and [n/2+1,n] otherwise." Works?

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

    Since both queries have the same length, their results will be both correct or both flipped. If the 1 is in $$$[1, n/2]$$$, the only 1 in $$$a$$$ will be in exactly one of the queries, so they will have different results. If not, the two results will be both 0 if not flipped or both 1 if flipped.

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

Is the proof for B correct?

"However, b cannot contain a: since a is not the entire p, a does not contain pn. However, b contains pn. Contradiction."

Doesn't really make sense

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

    Note that $$$p$$$ must be a permutation, so elements of $$$a$$$ being in $$$b$$$ implies that $$$a$$$ must be a subarray of $$$b$$$.

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

      I get that, but why would that be a contradiction?

      [1, 2] is a subarray of [1, 2, 3]. The first one doesn't contain 3. The second one contains.

      "b cannot contain a: since a is not the entire p, a does not contain pn. However, b contains pn. Contradiction."

      What's the contradiction?

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

        Evirir can you explain how is that a contradiction ? it should be like some element is a member of a but it is not in b then contradiction works isnt ? but which element to consider of a

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

        The contradiction is that $$$a$$$ must be a subarray of $$$b$$$, but $$$b$$$ cannot contain $$$a$$$ (i.e. $$$a$$$ cannot be a subarray of $$$b$$$). The two bullet points contradict each other.

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

          i mean to say you wanted to show that (a cannot be subarray of b) but the proof of that is not exactly showing that because its arguing about one element of b which is not in a , but for proof to work we would need to argue with one element of a which is not in b.

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

            Oh good point, thanks for pointing it out! I have edited it

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

Problem F is too implementation heavy

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

i like E a lot

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

Has anyone approached Problem D using recursive DP not iterative?

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

      Thanks, your code is quite clear and understandable

    • »
      »
      »
      4 weeks ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      Hello. Can you please explain the reason for checking from every possible position instead of just (n,m)??

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

        implementing recursion from (n,m) will lead to exploring m transitions in one call,instead I just explored every transition independently, in this way it is easy to code the recursion.

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

First 2 probs weren't that hard tho I got +1 each

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

The problem was indeed challenging, but the tutorial was fantastic! It broke down the logic so clearly that everything made sense and and easy to grasp. Huge thanks to the author for such straightforward explanation—it really helped me learn and understand the approach better

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

I was practicing old problems and could see Mex Destruction is exactly same as 1696B — NIT Destroys the Universe

https://codeforces.net/problemset/problem/1696/B

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

F can be solved through adding barriers instead.

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

I'm surprised how simple the solution to B is. During the contest, I created a list of segments to check the validity of the ranges. I have completely overlooked the easy solution.

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

My approach to F :

Part 1: What the F?
Part 2: Solve without updates
Part 3 : Handling updates

Submission : 299146450

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

can someone recommend dp problems which require optimization like in problem D ....thanks in advance