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

Автор intrusiv, 3 года назад, По-английски

Hello, Codeforces! Or, as we like to say in Romania: Dacă voi nu mă vreți, eu vă vreu, Codeforces!

I am glad to finally invite you to participate in Codeforces Round 915 (Div. 2), which will start on Dec/16/2023 17:35 (Moscow time). You will be given 6 problems and 2 hours to solve them.

The problems were supposed to be authored and prepared by cadmiumky, but in reality they were by tibinyte.

I would like to thank:

  • Say_my_name for LGM testing

Scoring Distribution: 500-1000-1500-2000-2250-2250

The problemsetters wish you good luck & have fun :)

Editorial is available here.

  • Проголосовать: нравится
  • +231
  • Проголосовать: не нравится

»
3 года назад, скрыть # |
 
Проголосовать: нравится -36 Проголосовать: не нравится
»
3 года назад, скрыть # |
 
Проголосовать: нравится +24 Проголосовать: не нравится

what was your contri in the round

»
3 года назад, скрыть # |
 
Проголосовать: нравится +14 Проголосовать: не нравится

Thank you sir intrusiv for teaching us what recherché means.

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

what's TBD ?

»
3 года назад, скрыть # |
 
Проголосовать: нравится +15 Проголосовать: не нравится

As a tester, the round is very nice and I wish you all to solve everything you can and get a high rating!!!

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

Hope to become Expert in this round

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

hope to solve E on this round

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

Another newbie tester?

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

newbie problem setter 😱

»
3 года назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

Why does it tell you a cheater when I hover your handle?

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

Будет круто, если я получу специалиста в этом раунде..)))

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

Hope I will be Legandary Grandmaster after this round !

»
3 года назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +3 Проголосовать: не нравится

How to become purple? i think i can solve E after the contest,but when i solve D ,100 minutes has been used ,so i dont have enough time

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

Excited for the round ?

»
3 года назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

Are tibinyte2006 and cadmiumky the same person ??

»
3 года назад, скрыть # |
 
Проголосовать: нравится +25 Проголосовать: не нравится

cf contests >>> university exam prep

»
3 года назад, скрыть # |
 
Проголосовать: нравится +14 Проголосовать: не нравится

As a tester, I really liked the problems, and I hope that you will like them too

»
3 года назад, скрыть # |
← Rev. 2  
Проголосовать: нравится -14 Проголосовать: не нравится

Does it rate?

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

Hope to be a Master this round!

»
3 года назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Hope to become pupil this time!!!

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

Hope to get to -39 rating after this round!!!!!

»
3 года назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

Geothermal will win Codeforces Round 915 (Div. 2)

»
3 года назад, скрыть # |
 
Проголосовать: нравится -8 Проголосовать: не нравится

is it rated?

»
3 года назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

STORY OF MY LIFE:


Day After Day, Inconsistency after incosistency,

Yet here I come, to solve another 3 problems and then get stuck at 4th, getting angry at problem setter for not explaining problem statement clearly, and in the end realising my own mistake and succumbing to my own dumbness and accepting that I am not made for this...

Till next time... ( Yet here I come, to solve another 3 .... )

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

Interesting score distribution; Looking forward to the round!

»
3 года назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

win114514 ORZ

Possibly the highest gain from a Div. 2 contest — rank 1 (barring FST) with prior rating: 2099

Edit: Apparently not anymore.

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

How to solve D?

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

    $$$MEX(a_1, \ldots, a_i) = min(a_{i+1}, \ldots, a_n)$$$ for permutations, therefore sum of prefix mexs == sum of suffix mins. After this observation problem is pretty standard, iterating over all cyclic shifts and recalculating cost in some way

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

    The way I solved it was to look from the end rather than the beginning — then the sum of MEXs is related to the sum of suffix minimums.

    Then I split the problem into two sub-problems: if you cut the array at a certain index and then swap the two parts obtained you get a cyclic shift. I solved the problem separately on those two parts. I did it in a very convoluted way with monotonic stack + binary search on a bunch of arrays but there is surely a better way.

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

    Segment Trees worked for me. Basically, found all initial mexes, and then, did cyclic shift one element at a time, calculating the updated mexes. So what should happen when removing a[I] from the start of the array is considered. All mexes greater than a[I] will fall to a[I], also, adding a[I] to the end again simply adds n to the mexes. This is just done for all I from 0 to n-1

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

    Another approach: compute mex values for the array, and encode them using run-length-encoding: RLE = [(mex1, cnt_mex1), (mex2, cnt_mex2), ...]. This array will have increasing sequence of mex values. Then you can implement left cycle operation: it will remove some of mex values from the end of RLE, and add two more values: [(x, removed_length), (n, 1)]. Doing so you can also keep total sum of mexes in the RLE. It is possible to show that such implementation gives linear complexity: https://codeforces.me/contest/1905/submission/237518768

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

Why O(n) didn't work for C ?

»
3 года назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Is cost function in D convex by any chance? I guess it's really not, binary/ternary search shenanigans were my last hope anyway.

A and B were almost too easy, difficulty of C was sensible, then it's just pondering problem D for the rest of the remaining time.

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

why trying to kill nlogn in D?

»
3 года назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +26 Проголосовать: не нравится

cool contest, although it felt like you should try to solve both D&E, but have too little time, 2 hrs 15 min would be better

how to solve E can anybody please tell? i think i got it at the end but im not sure

  • »
    »
    3 года назад, скрыть # ^ |
    ← Rev. 4  
    Проголосовать: нравится +31 Проголосовать: не нравится

    A $$$O(n)$$$ solution would be simulating the whole segment tree process, adding $$$v \times (2^\text{No. of leaves in left subtree} - 1) \times (2^\text{No. of leaves in right subtree} - 1)$$$ to the answer each time.

    By trying some smaller cases, you may observe that at each depth, the maximum difference of the range that the node represents are at most 1. So, for each depth, you can group the nodes into at most 2 sets, and then you can quickly calculate the contribution of each set of nodes to the answer (in $$$O(1)$$$ time complexity). The final time complexity would then be $$$O(log N)$$$.

»
3 года назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Problem A looks like John Conway's Game of Life.

»
3 года назад, скрыть # |
 
Проголосовать: нравится +17 Проголосовать: не нравится

Segment trees are not ugly, segment trees are poetic.

»
3 года назад, скрыть # |
 
Проголосовать: нравится +18 Проголосовать: не нравится

Probably overcomplicated B, but here's my thought process:

  1. It's always optimal to remove 2 leaf nodes at every stage.
  2. Naturally, we'd want to remove the farthest leaf nodes. In other words, we want to remove the diameter of the tree at each stage. Of course, finding out the diameter at each stage is tricky, but lucky for us, we don't have to print the choice of vertices.

Remembered about the Tree = edges of a diameter + forest representation from TheScrasse blog. Then, if you visualize the tree as forests hanging on the diameter, you can see that no matter how the diameter is computed, after each operation, the number of leaves reduces by 2. Hence, answer is $$$ceil(leaves/2)$$$.

Image

Submission

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

    Do we need to remove diameter leaves? I think it's ok to choose any pair of leaves, i might be wrong thou. I'm just asking

    • »
      »
      »
      3 года назад, скрыть # ^ |
      ← Rev. 3  
      Проголосовать: нравится +13 Проголосовать: не нравится

      Counter Example

      If you do a random merge:

      • Collapse 8 and 9. Vertex 6 remains.
      • Collapse 6 and 7. Vertex 4 remains.
      • Collapse 4 and 5. Vertex 2 remains.
      • Collapse 2 and 3.

      But, it can be done in $$$ceil(5/2) = 3$$$ steps. The catch here is to avoid creation of leaf nodes after merging, unless absolutely necessary (for example, when there's a single forest hanging on the diameter, except for this case, in all other cases, you can guarantee that if there are atleast 2 forest, leaf node counts will go down by 2).

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

      No, I think if you take any leaves at random, try taking adjacent leaves for Balanced BST

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

B?

»
3 года назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

Here is my screencast of solving all problems in the contest (HD will be available once YouTube completes processing)

I will also discuss how I solved all the problems in the post-contest discussion stream.

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

Do we needed tree/graph knowledge to solve B or do there was any other way to solve it.

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

How come the answer for B isn't just the ceiling of the number of leaves divided by 2?

»
3 года назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +1 Проголосовать: не нравится

C >>> B for me can someone please explain how to solve c?

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

    lets say the largest subsequence is zzba in the first iteration,then in the second iteration will be zzb, because after one right shift it becomes azzb,so now we cant take 'a' in the largest subsequence, this observation is very useful in solving this problem

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

guys why was my code outputing 1 less than the answer in B

ll t[maxn];

void run(){ ll n; cin >> n; for(int i =0 ; i < n; i++) t[i] = 0; for(int i =0; i<n-1; i++){ ll v,u; cin >> u >> v; t[v]++; t[u]++; } sort(t,t+n); reverse(t,t+n); ll c = 0; for(int i = 0; i < n; i++){ if (t[i] == 1) c++; } cout << (c+1)/2 << nl; }

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

A strange distribution of complexity. A very simple C, and a complex D for such a C.

Anyway, if someone solve D, how?

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

    Sorry I don't think C is easy, it's hard.

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

    let $$$mx_i$$$ be the highest index $$$j$$$ (0 based) such that $$$p_j \leq p_i$$$.

    Then the cost is $$$n^2 - \sum_{i=0}^{n-1} mx_i$$$.

    We can simulate cyclic shifting using a sum-segment tree that supports adding a number and assigning a value to a segment.

    See my code for more details: 237511939

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

    C (40+min) is harder to debug than D(20+min).... Because I misread it as substring lol.

    And I solve them using the same algorithm using the decreasing stack. For C it's to find a largest subseq, for D it's to find the min value on the right.

    For D, you can start with x x x x x x x 0 and then start to put numbers from left to the right. The mex of the new moved number is the min(moved number). Using a decreasing stack can maintain the count simply.

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

Hoping to become Pupil in this contest :)

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

How to solve C?!

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

    notice that the largest lexicographical subsequence after all the moves will get reversed (because it will be non increasing so doing the operation until it gets reversed is optima)

    so just reverse it and check if the string is sorted or no

    and the answer is (size of the subsequence) — (the frequency of the first element in it)

    you subtract the frequency of the first element because there's no need to shift the because the elements behind it will all come in front of it

    here's my submission

»
3 года назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +11 Проголосовать: не нравится

I confirmed with author that "sorted state" means "non-decreasing" close to the end...and i was trying to debug C for over an hour just because I output 0 instantly if the given array is non-increasing...

Shouldn't "sorted" be more clarified in statement?

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

has anyone tried dp on problem D? for two different cases: i < index[0] and i> index[0]?

»
3 года назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Operation "Problem A" Struggle Report

Hour 0: Entered the battlefield with confidence, assuming an easy victory.

Hour 2: Reality check. Explored different algorithmic approaches to tackle unexpected challenges.

Hour 5: Delved into online forums, particularly Stack Overflow, seeking insights from cryptic responses.

Hour 8: Consulted textbooks, tutorials, and documentation in a desperate quest for understanding, attempting to reshape the problem into familiar forms.

Hour 12: Embraced creative madness, resulting in a code resembling an abstract art piece – a chaotic masterpiece born from unconventional solutions.

Hour 15: Faced a low point but chose resilience. Rewrote code, refactored, and debugged tirelessly.

Hour 18: Pieced together fragments of wisdom, forming a makeshift strategy. The problem, once formidable, started yielding to relentless effort.

Hour 20: Eureka! A breakthrough moment! The culmination of struggle, frustration, and experimentation led to a working solution. Celebrated the hard-fought victory.

Verdict: The journey through the Problem A labyrinth was a relentless pursuit. From conventional to chaotic, desperate to creative, every avenue was explored. In the end, triumph emerged from the crucible of hardship. To fellow warriors: persevere, adapt, and conquer! #ProblemAStruggle #CodeWarriorPersistence

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

C is too hard for me. RIP my rating

try again next round

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

Did "D" literally 10 seconds after the contest :").

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

AHHH Why can't my segment tree pass problem D

My algorithm
»
3 года назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

This is the 4th Div. 2 in a row I solve the first 3 problems, any advice to start solving D's ?

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

    Convert it into another problem. We want the n + (maximum possible sum of (minimum suffix array) over all possible arrays from shifting)

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

    Stuck at 3 problems as well. For me, if D is some math issue that I cannot solve even if I have 24h, then I will let it go. If it's something just related to the algorithm, I will spend more time to upsolve it after the contest. By shortening the solve time, I can sometimes finish D now.

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

can someone please explain how B is ceil(leaves/2)?

»
3 года назад, скрыть # |
 
Проголосовать: нравится +14 Проголосовать: не нравится

choking on B by thinking about diameter of the tree :v

»
3 года назад, скрыть # |
 
Проголосовать: нравится +14 Проголосовать: не нравится

You really couldn't come up with a name for problem F, could you?

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

does anyone use segment tree for problem D?

»
3 года назад, скрыть # |
 
Проголосовать: нравится +14 Проголосовать: не нравится

Just a heads up: Is it allowed to compress the code and execute it to make it difficult to hack? Example submission Last line is the obfuscated code: exec(decompress(b'\x1f\x8b\x08\x00s\xc2}e\x02\xff..')

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

Any idea why this fails for C?

Also, todays ABC C and CF B are kinda same, there you remove nodes, here you remove paths of nodes.

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

Excellent problems!

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

I advise the authors to study what segment tree are, because they don’t know

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

ooops, maybe I never become pupil! only two solves!

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

How to solve C?

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

    Part 1 : Finding the lexicographically largest substring.

    Hint : If you iterate end to start and maintain a char (largest so far), and if current char is largest, include it.

    Part 2 : Note that only these characters (or a subset of them) are part of every move Hint : Every time the set reduces by exactly one character

    Part 3 : You observe that the set of characters selected in 1 will eventually be reversed.

    Part 4 : Can you construct a string where (step 3 is fulfilled)

    Part 5 : check if string is sorted.

    Nice Move ? : Intentionally left one edge case for you to solve.

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

Can anyone tell me logic of Problem D

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

    Note — the answer depends on the last element, then the next smaller element left to it...and so on till it reaches 0.

    Shift the array such that 0 occurs at the 1st position,

    now ans[i] = ans[previous_smaller_position[i]] + array[i]*(i-previous_smaller_position[i]);

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

I got pretest passed for "A. Constructive Problems". Since my solution wasn't Accepted, does this imply that it was wrong? Please guide.

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

AC code

TLE code

How when I add this line get an AC?

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

someone explain me the proper logic behind B please

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

    in every operation you can choose u and v as leave nodes and compress them. so in every operation you can decrease total no. of leaves by 2 so if no. of leaves is even it will take leaves / 2 operations. if no. of leaves is odd it will take leavs / 2 + 1 operations. ans = (leaves + 1) / 2.

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

Hello. There is an issue on the task C. During the contest, I had sent my code with c++20 and got TL. 237525118 But after the end of the cf I sent the same solution on c++17, and it was accepted.237531478

Pls do something with that.

»
3 года назад, скрыть # |
← Rev. 4  
Проголосовать: нравится +6 Проголосовать: не нравится

It appears that there is a discrepancy in the Problem C description. The task requires sorting a given string, but the sorting criteria are not explicitly defined. However, the jury's answer specifies that the output should be in non-decreasing order. This creates confusion because, for example, the input string dccbba is already sorted in non-ascending order, but the jury's expected output is 5. In contrast, the output could also be 0 since the string is already sorted. wdyt? intrusiv tibinyte2006 cadmiumky

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

Can anyone please help me understand why changing the CPP Version is resulting in different behaviour with the same code.

https://codeforces.me/submissions/ma_da_fa_ka

I got ACCEPTED, TLE, RTE with different version of cpp compilers.

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

Problem D: We can use Binary lifting if the input array was not always a permutation of set $$$(0,1,2,..,n-1)$$$

Submission: Link

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

Why is my D getting TLE ? I tried to optimise the inner loop by jumping to the next smaller element each time using a stack, it should not be N^2 ?

237525237