sammyuri's blog

By sammyuri, 4 months ago, In English

Thank you for participating in our round! We hope you enjoyed the problems as much as we enjoyed preparing them.

Rate the contest!

2229A - Slimes on a Line

Idea by: Intellegent

Prepared by: Intellegent

Editorial by: reirugan

Hint 1
Hint 2
Solution
Code
Rate the problem!

2229B - Absolute Cinema

Idea by: Intellegent

Prepared by: Intellegent

Editorial by: reirugan

Hint 1
Hint 2
Solution
Code
Rate the problem!

2229C1 - We Be Flipping (Easy Version) 2229C2 - We Be Flipping (Hard Version)

Idea by: Intellegent

Prepared by: Intellegent

Editorial by: reirugan

Hint 1
Solution (Easy Version)
Hint 2
Solution (Hard Version)
Code (easy version)
Code (hard version)
Rate the problem! (easy version)
Rate the problem! (hard version)

2229D - Me When Median Problem

Idea by: Intellegent

Prepared by: Intellegent

Editorial by: reirugan

Hint 1
Hint 2
Hint 3
Solution
Code
Rate the problem!

2229E - Deconstruction Tree

Idea by: Intellegent

Prepared by: Intellegent

Editorial by: Intellegent

Hint 1
Hint 2
Solution
Code
Rate the problem!

2229F - Load Unbalancing

Idea by: myst-6

Prepared by: sammyuri

Editorial by: sammyuri

Hint 1
Hint 2
Hint 3
Solution
Code
Rate the problem!

2229G - Roadworks

Idea by: sammyuri

Prepared by: sammyuri

Editorial by: sammyuri

Special thanks to Geothermal for the absolute cinema solution!

Hint 1
Hint 2
Hint 3
Main Ideas
Solution (Boring)
Hint 4
Solution (Absolute Cinema)
Code (Boring Solution)
Code (Absolute Cinema Solution)
Rate the problem!

2229H - Wowee Binary String

Idea by: Intellegent

Prepared by: Intellegent

Editorial by: Intellegent

Hint 1
Hint 2
Solution
Code
Rate the problem!

2229I - The Endians

Idea by: sammyuri

Prepared by: sammyuri

Editorial by: sammyuri

Special thanks to p0tato for the absolute cinema solution!

Hint -1
Hint 0
Hint 1
Hint 2
Hint 3
Hint 4
Main Idea
Solution (Boring)
Solution (Absolute Cinema)
Code (Boring Solution)
Code (Absolute Cinema Solution)
Rate the problem!
  • Vote: I like it
  • +304
  • Vote: I do not like it

»
4 months ago, hide # |
 
Vote: I like it +16 Vote: I do not like it

thanks for the contest and editorial, ac on c1 honestly kind of brought tears to my eyes, definitely going to upsolve c2

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

Thanks for fast editorial!

»
4 months ago, hide # |
 
Vote: I like it +16 Vote: I do not like it

The contest and the editorial are absolute cinema.

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

Enjoyed the contest Couldn’t think of binary search on D :(

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

Thanks for easy B

»
4 months ago, hide # |
 
Vote: I like it +69 Vote: I do not like it

F no-binary search $$$O(3^{n})$$$ solution:

We maximize the minimum value of $$$B$$$, then add the largest remaining element.

Let $$$dp[msk]$$$ be the max number of groups whose supermask is $$$msk$$$.

We sort all masks $$$m$$$ in order of largest sum to smallest sum, then we add them to the $$$dp$$$. Obviously the largest sum where after we insert its' mask, $$$dp[msk] \geq k$$$ becomes true is the maximum min-sum we need to find.

Updating $$$dp$$$ is really easy, $$$dp[msk \vee m] = max(dp[msk \vee m], dp[msk]+1)$$$ where $$$msk \wedge m = 0$$$.

If we do it stupidly, then obviously it's $$$O(4^{n})$$$, but we can obviously just iterate through all $$$msk$$$ that satisfies in $$$O(3^{n})$$$ total.

There's both a $$$O(n2^{n})$$$ and $$$O(2^{n})$$$ way to get the final result, both of those should be extremely trivial.

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

Why did it feel like C2 > D :sob:

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

    You actually can do dp with backtracking array to know which element is best to chose, after that it should be easy to solve the problem since you now just need to construct the order of moves :)

    here's the code
    • »
      »
      »
      4 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Could you please explain how it works? I also thought to do dp but couldnt implement it

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

        for every element that is positive you try to take it as it self or, change it to -a[pos] (you can think about it as take it or leave it, take it = -a[pos], leave it = a[pos]), then check what's the maximum answer and backtrack to take the numbers

        after that, C1 is subtask of C2 make every element before the element you changed negative

        now change this element

        congrats the array is maximized

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

          yay ty

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

          what does ok mean in your rec function?

          why does it allow a sign flip operation when your a[pos]<0 && ok=1? could u please clarify that.

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

Problem D broke me down. I just couldn't figure out how to check if mid is valid answer or not. Can anyone share the intuition behind finding the validity check for mid.

  • »
    »
    4 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it +7 Vote: I do not like it

    Instead of dealing with 2 arrays, compress them into one. The only thing you need to track is the frequency of 1 at each index to retrieve the original arrays (the ordering of $$$a_i$$$ and $$$b_i$$$ does not matter since we would anyway sort them at the end).

    Define $$$F[i] = a[i] + b[i]$$$. Then this array contains $$$0$$$, $$$1$$$ and $$$2$$$, and you have to keep on merging elements of this array. If you can retain a $$$2$$$ at the end, your mid is valid.

    Notice that when $$$1$$$ merges with $$$x$$$, it produces $$$x$$$. So, you can remove all $$$1$$$ from $$$F$$$. Now it only contains $$$0$$$ and $$$2$$$.

    Notice that when $$$x$$$ merges with $$$x$$$, it produces $$$x$$$. So you can compress all identical copies of $$$0$$$ into 1 copy. Same for $$$2$$$.

    So now, the array $$$F$$$ looks like

    $$$ 020202020 \dots $$$

    Finally notice that when $$$0$$$ merges with $$$2$$$, it produces $$$1$$$, which was an identity element. In other words, $$$0$$$ eats a $$$2$$$. Therefore, if the runs of $$$2$$$ is strictly greater than the runs of $$$0$$$, then you will retain a $$$2$$$ at the end and your mid is valid.

    Note that it's better to compress all 0s to a single element, but a run of 2 can survive being eaten by 2 0s.

    For example, $$$000222000$$$. Here, you can compress it like so $$$02220$$$. Then, the first $$$0$$$ eats the first $$$2$$$ and the last $$$0$$$ eats the last 2, and the middle $$$2$$$ still survives.

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

    To check if mid is valid or not, you just need to count the indices (say cntg) where both a[i] & b[i] >= mid and subtract from it the count of indices (say cntl) where both a[i] & b[i] < mid (plus either one of them >= mid and other < mid). More importantly, to count the indices for numbers less than mid you need to count them as a contiguous subarray i.e. if elements from index i1 to i2 contains numbers such that both a[k] & b[k] < mid for all k from i1 to i2 then count it as one subarray. You should only count this subarray in cntl only when if there exist atleast one index such that both a[i] & b[i] < mid and the others can be either both a[i] & b[i] < mid or a[i] >= mid & b[i] < mid or vice-versa, otherwise if it's a subarray of only the one >= case then you can ignore this subarray.

    Then if cntg > cntl for this mid => this mid is a possible answer and you search for a higher one otherwise you search for lower answer.

    why cntg > cntl : for some index i (say this is an index with both a[i] & b[i] >= mid), if i + 1 is an index with one of a[i] or b[i] >= mid then you can get the answer as mid but if both of them are < mid then out of these four values you will get one < mid and other >= mid which is uncertain

»
4 months ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

Again, this is the 2nd time we've gotten a problem named Absolute Cinema with a problem quality rating but Absolute Cinema is not a choice for rating, you even put it in the overall contest rating, come on. Literally unsolvable

o72 contest tho

»
4 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

I solved D differently, I tested the best move to pick is to get the index where s2+s3 is min and repeat for n-1 times will lead to the optimal answer. (I don't have proof tho, I intuitively think that pushing the min of 2 median will eventually lead to the final median is max)

So the rest is just applying the fit data structure for the job (sorted multiset to get min, linked list to modify then next and back elements).

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

    So now i am not the only one who figured this out.

    But I am not able to implement this, can you share your implementation of this approach?

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

    This is an amazing solution that attracts me!

    From my perspective, there is a way to proof via coding.

    The structure in this problem is like a list, so it's not easy to prove it directly. But we can focus on a easy situation that $$$n=3$$$, and we can brutely iterate through all permutations:

    Code

    Then for $$$n \gt 3$$$, we can just swap adjacent pairs to make the operation sequence fit our condition without making it worse.

»
4 months ago, hide # |
 
Vote: I like it +10 Vote: I do not like it

It was a great contest .. Although I lost rating points but learnt valuable lesson today .. will definitely upsolve C2 and D

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

Wow, I hate my network.

Why couldn't I open the submit page in the last minute when I was trying to submit my code of F which got an AC when I submitted it later :(

Rank dropped from 100+ to 350+ because of that.

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

Being a beginner, I was happy to solve both A and B in this contest & was expecting an increase in rating but still got -55, can anybody guide me further? how to learn techniques of solving C and above? I myself felt A and B were comparatively easier but still I wasn't expecting a rating drop. Suggestions & tips are appreciated, Thanks

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

    There comes no surprise that solving 2 problems will get a poor rank and a decrease in rating.solving C1 requires us to observe that you can just turn the all numbers into negative.

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

Could someone tell me why is this O(nlog2(n)) getting TLE on E:https://codeforces.me/contest/2229/submission/375856455?

I thought that O(nlog2(n)) would pass comfortably

nvm I found that I did a mistake when setting the parent of a node in the dfs

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

I believe F is AC-able using simulated annealing, but I just don't know how to set the TL for each test case.

»
4 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it
»
4 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

C1 is a good hint for C2

»
4 months ago, hide # |
Rev. 2  
Vote: I like it +28 Vote: I do not like it

$$$\mathcal O(k^n\cdot n\log A)$$$ problem F with pruning optimizations in 62ms.

https://codeforces.me/contest/2229/submission/375829263

»
4 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

That awesome moment when u realize C1 approach fits into C2

Absolute Cinema

»
4 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

Is it now kind of normalized that amount of cheaters is insane?

Every account I open in top 500 which are not red is either new or recently opened account.(straight up acsending ranks) most of the time, like almost 90 per cent

Can't we do something about this?

The number of people who solved D also looks very suspicious.

»
4 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

I got accepted in problem D by just using a priority queue. Can anyone prove this submission is right or not? If not, can anyone hack me?

375817147

»
4 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

The contest as genuinely difficult but compelling, I enjoyed every step.

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

What's the expected rating of E ?

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

My solution for D

consider binary searching on the answer

now transform a[i] = 1 if a[i] >= mid else -1 b[i] = 1 if b[i] >= mid else -1

now let c[i] = a[i] + b[i]

notice that c[i] is either -2, 0 or 2

we want to achieve sum of c >= 2 since every operation either remove 2 1s, 2 0s or 1 one and 1 zero

so if sum >= 2 we can just keep removing 1 one and 1 zero and when possible remove 2 zero so since sum >= 2 we will be left with 2 ones

what about the else case

in that case notice that merging a 0 with any element makes no difference so remove them

now merge all consecutive blocks of -2 and replace with single -2 like instead of -2 — 2 -2 do a single -2 and remove all other

now we have off form -2 2 -2 2

notice if we merge a 2 and -2 the set will be 0 0 1 1 so 0 1 so merging -2 and 2 will produce a 0 it makes no difference to perform operations from now

so now just check if the sum of this given array is >= 2

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

My solution to D is little bit different the idea is similar but the way is_it_possible function works is much different.

I considered pivot points as {1, 1} then in between these pivots values are either {0, 0} or {0, 1} then I tried to remove as many {0, 0} via submerging them with adjacent {1, 1} then array becomes shrinked array to {0, 1} or {1, 1} values then I just applied the said operation of finding 2 median elements repeatedly across the array and at the end if any 1 is pending then yeah we found that is possible.

»
4 months ago, hide # |
 
Vote: I like it +10 Vote: I do not like it

If I understand correctly this part of the problem E author's implementation is UB. When $$$n$$$ is a leaf s becomes empty and we dereference end() iterator.

for (int u : cur){
   if (u > (*s.begin()))
      ok[u] = true;
}
  • »
    »
    4 months ago, hide # ^ |
     
    Vote: I like it +5 Vote: I do not like it

    Good catch, I updated code to fix this. I'm unsure if this UB would actually cause any issues since when $$$n$$$ is a leaf the code ignores most of the computation anyway, but maybe something really weird happens.

»
4 months ago, hide # |
Rev. 2  
Vote: I like it +169 Vote: I do not like it

Problem F can be solved in $$$O(n 2^n)$$$ time.

Since we can examine every permutation of items to pack into groups by $$$O(n 2^n)$$$-time DP, we can choose which group is packed first as we like. Now we want the last packed group to be the smallest. A sufficient condition is $$$(\text{weight of the first group}) \times (k-1) \geq (\text{weight of the remaining items})$$$ for all $$$k\geq 2$$$.

Consider performing DP with this condition but without setting the target weight. Groups except the last one will not be (essentially) the smallest under this condition, so it is optimal to finish those groups as early as the condition is satisfied.

Submission 375925096

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

There is a randomized solution for F which I couldn't prove
Here it is 375940169

The idea here is that we start from a random permutation of $$$a$$$ and later try local optimization (to be exact, swapping 2 elements and check whether the answer has increased)

I have no idea for a formal proof and also no idea how to construct a counterexample
This seems to work really well though
My official in-contest submission passed pretests, but failed system tests due to only swapping each pair of indices once, but sometimes it's not enough

Some of my intuition behind this solution is that the constraints are fairly strict and you can't generate many cases with $$$n = 18$$$, but this is where the algorithm would struggle the most
And for the smaller cases it can basically perform checks on all the permutations there are

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

    Good solution! In my humble opinion, maybe it's a better choice to randomize the order we enumerate the pairs. I submitted 6 times and the solution was accepted every time :)

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

I couldn't figure out problem 'D' , I was wondering if all those combination can be figured out with backtracking and hw i appy sorting on and in each dfs... It is hard

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

375790778 for this solution i just optimize my previous approach what was like i flip the every prefix element then i did only flip parity coz it reduces my T.C to n^2 to n. just it is.

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

great contest

»
4 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

My solution for D

Approach : The question states that we have to maximize minimum, therefore is a potential candidate for BS on answers. Let the numbers >= x be treated as 1 and those less than it be treated as 0, therefore binary arrays are created. now our goal is to check whether the maximum of the minimum is gonna be 1 or not, if it's 1, then it could be the answer, and then reduce the search space by low = mid + 1.Ok, so it means that the final reduction should be 1 1, tp achieve it, we try to make a block of 0 0 equivalent to a single 0 0, and their cnt should be increased by 1, and cnt of 1 1 should be added whenever encountered, and if at the end the cnt11 > cnt00 then it's a possible answer, else do high = mid-1.

My submission : 376107418

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

This is the best Div.1+Div.2 contest I have ever seen!Problem C2,F,G,H,I are all really difficult and worth studying.

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

Problem I. The O(n^2) tree dp is actually more strongly bounded by O(nk), right? I feel like I’ve seen a similar problem somewhere before, but I can’t remember which one it was.

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

Hacking challenge: absolute ass solution 376266084. I just slapped some ifs on a type of bruteforce.

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

awesome editorial

»
4 months ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

I really don't understand, is D only a R1700 problem?? Is the average level increased for CF or is it because of AI ??