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

Автор Newtech66, 5 лет назад, По-английски

Hello, Codeforces!

TimeWarp101 and I are excited to invite you to Codeforces Round 782 (Div. 2) which will take place on Apr/17/2022 17:35 (Moscow time). This round will be rated for participants with rating lower than 2100.

Many thanks to all the people who made this round possible:

You will have 2 hours to solve 6 problems.

Scoring distribution: $$$500-750-1500-2000-2250-3000$$$

We've tried to keep the statements short and pretests strong. We hope you will enjoy the round!

See you all in the standings!

P.S. namanbansal013 will be livestreaming his solution explanations for some of the problems here. Do check out his channel too!

UPD: We are really sorry for the issues with the queue, but we hope you liked the problems anyway.

UPD: Editorial

UPD: Congratulations to the winners!

Official winners:

  1. Fire_big
  2. 20333333333
  3. _DAC_
  4. SILA_edr
  5. Nutella3001

Unofficial winners:

  1. Geothermal
  2. disorientation
  3. Koosha_Mv
  4. tute7627
  5. oleh1421

First solves:

  1. A: SSRS_ at 00:01
  2. B: SSRS_ at 00:03
  3. C: PurpleCrayon at 00:07
  4. D: noimi at 00:17
  5. E: CoderAnshu at 00:21
  6. F: rainboy at 01:06
  • Проголосовать: нравится
  • +469
  • Проголосовать: не нравится

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

Interesting tags.

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

Good Luck everyone!!

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

As a tester,

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

Soooooooooo excited!!

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

Probably one of the best Div2 rounds I've tested this year ;)

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

As a tester I will say problems are are very good and interesting.

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

where anime girl?

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

Can you tag me for being a deadly pillow?

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

I wish everyone high rating and may you solve your next alphabet { C for me :) }

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

" We've tried to keep the statements short and pretests strong. We hope you will enjoy the round! "

best of luck

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

As the legendary AwakeAnay has tested this round, it must be legendary as well. Don't forget to take part!

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

The contest is held at my birthday :D

Hope for luck so I am not longer hard stuck in candidate master :)

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

Last two rounds were unlucky for me( Wish this round would be one of the best rounds!

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

Hope I can make it to cyan this round. So close.

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

As a tester, this is the first round I've ever tested!

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

"i_am_completely_useless for being completely useless." -- Sakura :))xD

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

As a not tester of the round i hope that it would be good

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

Good Luck All!!!

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

I'm pumped!

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

As not a tester, give me positive contribution.

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

As a tester, I am a tester.

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

As the last contest as a newbie for me :3

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

Indian rounds are always interesting, most of them have a lot of math problems)

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

Excited

Wooooooooooooooooooooooooooooooo!

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

Remember, if you see this name antontrygubO_o, this is gonna be another XorForces contest.

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

SOOOOO EXCITED ABOUT IT!!!

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

https://youtu.be/CVC2gQY8V1k

doki doki waku waku~

I've been obsessed with this song lately

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

good luck for everyone

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

Thank You all for arranging such a wonderful contest.

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

As it is mentioned statements are short and pretests strong , it would be more interesting.

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

Hope I turn Pupil this round :)

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

So, what topics of JEE are we gonna revise today? :)

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

As a contestant, I wish all of you good luck!

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

I hope that pretests are strong

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

Bad difficulty of A.

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

Yes, you guys really have kept the statements short. Good job!

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

queue!!!!

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

Am, I the only one, who is facing server problem

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

My code is in queue for too long. What should I do?

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

mm

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

i sumbitted my same code twice , one at the main site (which crashed due to queue) and another at the alternate cf site after reloading ...now both have passed prestests , plz consider my first code and remove penalty! Newtech66 MikeMirzayanov P.S. Thnx , my 2nd sumbission got skipped.

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

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

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

Is it just me or problem's difficulties kinda messed up today?

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

C < B < A, cool round. But D is very interesting

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

I had such a hard time solving A. Hopefully my last submition goes through system testing XD

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

It was the worst contest this year.

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

    Maaaaaaaaybe, but contests this year were all reaaally good so that woudln't be anything bad.

    Problem A was too hard — that's for sure.

    Problem B was kinda boring, but implementation heavy and bug prone (at least in my case).

    Problem C was really nice though.

    Problem D was nice as well.

    Not sure about rest as I didn't read them.

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

Key observation for E (Hopefully obvious for most people): The answer can only be between 0, 1, 2. Then it just boils down to having dsus for each bit.

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

    I know that answer can only be 0, 1, 2, and I can find when answer is 0. But how to find when asnwer is 1?

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

      So basically what I did was I maintained the dsus for each bit and an extra dsu just for zero-length edges. Then, for each edge, we examine whether if its length is odd or even. If it is even, then we mark both nodes as "good" as using this edge would ensure that the and-sums would never reach 1. Then, for each of the dsus, except for the one maintaining $$$2^0$$$ bit, we mark the components that has a good node to be good since it means that within the component, there is a path/walk to a good node and whilst doing so, the and-sum would never reach 1 as all the edges within this particular dsu would have $$$2^k$$$ bit set throughout. Thus, to check if the answer is one, we just check for each of the dsus (obviously except for the $$$2^0$$$ bit dsu), we check if the component is "good" and if so, the answer should be one.

      P.S. Sorry for a long, messy explanation

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

      the idea for how to determine whether or not the answer for $$$(v,u)$$$ can be 1 is that since the path prefix AND is non decreasing there will be a point in the path $$$v \rightarrow v_{0} \cdots v_{i} \rightarrow v_{i+1} \cdots \rightarrow u$$$ where the prefix AND of $$$v_i$$$ to $$$v_{i+1}$$$ jumps from a value $$$x$$$ to something even where $$$x$$$ is odd and bigger than $$$1$$$, this is equivalent to $$$x$$$ having the $$$0^{th}$$$ bit on and at least one other bit on. we can check for this by iterating what the one other bit can be. setup 30 dsu with the $$$i^{th}$$$ dsu only using edges with weight having both the $$$0^{th}$$$ and $$$i^{th}$$$ bit on. the answer can be $$$1$$$ if for one of the dsu's there exist an edge from $$$v$$$'s cc to outside of $$$v$$$'s cc such that the AND value becomes even

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

solutions from B to D can be found in youtube.

https://www.youtube.com/channel/UCVul5dRaN-0ZUpwMdOjfiug/videos

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

Noice round!!! But A could've been a little bit on the easier/non-complex side!

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

when pretest 2 is given and you don't check that and make error in pretest 2 .

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

A candidate master should be able to solve problem A on a div2...

That aside, problem E seemed nice, even though I can't solve.

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

Good problems. And don't make any problem or contest anymore.

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

Any hints to solve A ?

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

Really wack contest.

»
5 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +12 Проголосовать: не нравится
  • I couldn't solve A. Felt that it was misplaced, or maybe I'm just not good in solving constructive problems.
  • B idea was nice. Implmentation was also okay.
  • I got the idea for C 5 minutes after contest ending. A good problem in my opinion.
»
5 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

How to solve D?

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

    (I didn't have time to finish it, but it seems to work mathematically)

    sum(all) / n = amount of 1 = s

    then we go from the end, realize was the 1 on n — 1 pos initially (it was if the value == n) simulate the cancellation of last addition on the suffix using a tree of segments (-1 on s length suffix), s -=1 if there was 1,

    solve the problem for n — 1

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

    Work backwards from n-1 all the way to 0. 153940196 Only accepted after contest ended.

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

    Try to find the zeroes present in the array. If c[0]!=0, then ar[0]=1 else ar[0]=0, with the help of c[0] we can find where is the 1st zero present in the array. let's say 1st zero presents at the jth position, then ar[0]*(i=0)+1*(j-i)+0*(n-j)=c[0]. With the above formula, we can find where the 1st zero presents in the array. Similarly, we can try to find the 2nd,3rd, and nth zero.

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

this time i am proud to solve A !

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

I feel that A and B are harder than usual contests. C is in normal difficulty. D is interesting: I came up with a rough construction very quickly but finalizing every detail took me a long time.

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

problems a and b are very hard as unusual !!

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

Any hints to solve b and c?

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

Make this round unrated all the solutions were leaked on youtube

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

Those who solved A after getting wrong answer at pretest 3, what was the corner case you considered?

My approach, but getting WA: There are b+1 gaps to put r characters, so the number of red chars per blue char would be either r/(b+1) or r/(b+1) + 1.

Repeat of sequence x r's & 1 b the viable number of times, and add any remaining characters. Cant figure out what is missing. Thanks a lot for reading

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

What your sorry will help me ??

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

it's been a while since problem A wasn't a one liner

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

Did the solution for F involve calculating the diameter of the tree?

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

153940198 153938389. Agony. I was 20 seconds too late with the accepted one

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

problem E: get the idea that answer could only be 0, 1 or 2. Got how to check 0. Got idea to merge one bit along with 1. But didn't find out how to check if 1 is possible.

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

    For each vertex, if there is an edge that connect with this point and whose value is even, set the vertex as an “ok” point(that means if you walk to this point while the and number is not 1,then 1 will not exist.). Use DSU 30 times for each bit(edges whose value in this bit is 1).Query in DSU[1..29],if the block which vertex u is in has an "ok" point, that means we have a way to protect 1 from exist.

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

    To check for 1: the path will be one such that it won't have 1 and then it'll have 0's. So that means that that last number before the 0's will have some bit that isn't 1. For each bit, consider the paths including that bit. Inside of a connected component of the edges that have that bit, we can get a path that passes through every vertex and also every edge in that component (that minimizes the number of set bits in the AND of those edges) then we'll want to use some jump starting from that component that sets the AND to 0.

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

    You could have a look on my explanation above : Comment

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

How to do B??

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

    greedily try from left to right. if the parity of K and s[i] is same and there is still operations left, set ans[i] as 1. For the last digit, you have to set all left K on it.

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

    Look from different perspective: first the whole array swap k times and each time later we change one element. Then it's optimal to set as many element in the left as one as possible. This can be done in left to right order.

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

I think solutions to D is

You can get the total number of 1s by taking the sum of input divide by the size. The reason for this is each 1 in the array add to the sum exactly n times.

We can figure out the value of the last index easily, it should be fixed for n-1 times.

We will solve this one by one from the last to the first.

Let say after you sort the array at length 5, you got 00011xxx, then it's obvious that if there are more than 2 0s that come after it, it will push over the 1s and will become 0. You can use binary search to find out how many times the value of index ith remains 0 (assuming you already figure out what come after it);

So just figure out the bit 1 by 1 from last index all the way to first index.

AC submission: https://codeforces.me/contest/1659/submission/153945063

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

Hello, I'm new here. Why does it say that I am registered for practice? Does that mean the contest was unrated for me?

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

I figured out a solution of Problem D using Segment Tree though I have no time to finish it during the contest, any other simple ways of solutions? 153940308

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

WTF!

Why still rated since the judge server was down for 15 minute?

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

Problem F is much more difficult than other DIV2 contest, I'm so poor at Game Theory

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

    F for me was basically write a stupid solution that solves the problem for all states (permutation, vertex) of a tree then making one observation (if the graph isn't a star graph then Alice always wins) and some case bashing, not interesting at all. Hopefully the editorial has some proof.

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

      I really enjoyed solving F (I managed to prove everything during the contest, and getting AC 1 minute before the end of the contest was very exciting).

      Anyways, here's the proof for why the diameter being at least 3 is sufficient for Alice to win:

      I'll use edge move on some edge connecting vertices $$$a$$$ and $$$b$$$ to denote swapping $$$a$$$ and $$$b$$$ in our permutation, and $$$dist(a,b)$$$ to denote the number of edges on the unique simple path from $$$a$$$ to $$$b$$$.

      Lemma 1: Given any tree and any permutation $$$p$$$, only doing edge moves on this tree can sort the permutation.

      Proof of Lemma 1: If we show that a sequence of edge moves can swap any two (not necessarily adjacent) values, we can clearly sort any permutation. Suppose we want to swap values $$$a$$$ and $$$b$$$, and the unique simple path in the tree connecting them is $$$a=v_1,v_2,\dots,v_k=b$$$, where $$$v_i$$$ and $$$v_{i+1}$$$ (for all $$$1 \leq i \lt k$$$) are connected by an edge denoted by $$$e_i$$$. We can see that doing the following edge moves in order: $$$e_1,e_2,\dots,e_{k-1}$$$ cyclically shift the values $$$v_i$$$ to the right. Hence first cyclically shifting $$$v_1,\dots,v_k$$$ once and then cyclically shifting $$$v_1,\dots,v_{k-1} \,\, k-2$$$ times, swaps the values $$$a$$$ and $$$b$$$, while not changing the positions of the other values in $$$p$$$.

      Now we just need to show Lemma 2: As long as the diameter is at least 3 (i.e. there exists a simple path with at least 4 vertices), we can make any edge move regardless of the current $$$x$$$, while not affecting other values in $$$p$$$.

      Proof of Lemma 2: Let's denote the vertices of the current edge move we want to make as $$$a$$$ and $$$b$$$. Then we have 3 cases:

      Case 1: $$$x \not\in \{a,b\}$$$ We can simply make the swap.

      The other two cases are simply split into whether the edge $$$(a,b)$$$ lies on the side of the diameter (i.e. exactly one of $$$a$$$ and $$$b$$$ has degree 1), or both $$$a$$$ and $$$b$$$ have degree at least 2. In both cases, we will rely on one or two "pivot" vertices. From here on, WLOG we assume $$$x=a$$$.

      Lemma 2.1: If there exists a vertex $$$d$$$ such that $$$dist(a,d) \geq 3$$$, then we can swap $$$a$$$ and $$$b$$$. Proof: Doing the following swaps always works: $$$(b,d)$$$, $$$(a,d)$$$ and $$$(d,b)$$$. Note that the parity handles $$$x$$$ avoiding $$$a$$$ and $$$b$$$, while the distance constraint means Bob can't reach $$$d$$$ in time.

      Case 2: Edge $$$(a,b)$$$ lies on the side of the diameter. Note that the case of $$$a$$$ being on the side (i.e. having degree 1) is handled by Lemma 2.1, as there must be a path of at least two vertices connected to $$$b$$$ (otherwise the diameter would be 2). Hence we only need to show the case where $$$b$$$ is on the side. Suppose the diameter (or a part thereof) is $$$b-a-e-d$$$.

      Then we make the following swaps (I'll use $$$(y,z)$$$ for swapping $$$y$$$ and $$$z$$$, $$$\rightarrow_v$$$ to show Bob moved $$$x$$$ to $$$v$$$, and $$$\overline{p_1p_2\dots}$$$ for the current relevant part of $$$p$$$. Additionally, I'll list all relevant Bob's moves, in case a move isn't listed, a strategy equivalent to Lemma 2.1 applies): Initially, $$$\rightarrow_a \overline{abde}$$$. Then $$$(b,d) \rightarrow_e \overline{adbe}$$$. Then $$$(a,d) \rightarrow_d \overline{dabe}$$$. Then $$$(b,e) \rightarrow_e \overline{daeb}$$$. Then $$$(d,b) \, \overline{baed}$$$, if $$$\rightarrow_a$$$, $$$(d,e)$$$ works, otherwise if $$$\rightarrow_d$$$, the trivial case of Case 2 applies.

      Case 3: Both $$$a$$$ and $$$b$$$ have degree at least 2, suppose the diameter (or a part thereof) is $$$e-a-b-d$$$.

      Then (using the same notation as above), the following moves work: initially $$$\rightarrow_a \overline{abde}$$$. Then $$$(b,d) \rightarrow_b \overline{adbe}$$$. Then $$$(a,d) \, \overline{dabe}$$$. If $$$\rightarrow_a$$$, $$$(d,b)$$$ works, otherwise if $$$\rightarrow_d$$$, the trivial case of Case 2 applies.

      Finally, note that Lemma 1 can be dropped altogether, but that means you need to additionally handle the cases where a desired swap $$$(a,b)$$$ isn't connected by an edge.

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

        So that's the proof for diameter at least 3 being sufficient for Alice to win? How about the cases that the diameter is less than 3? lol

        For me personally, it was clear that diameter at least 4 would work before writing the brute solution, good to know that proving for 3 is way harder.

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

          Oops, I found the first part harder to prove, so I just gave the proof of that, but here's the proof for the rest of the problem, which I actually find more interesting and cute.

          Let's denote $$$m$$$ as the center of the star (the tree).

          First, if $$$p$$$ is already sorted, Alice trivially wins.

          Next, if $$$p_m \neq m$$$ (i.e. $$$m$$$ is not in its position yet), we can see that if $$$x=m$$$ or $$$x=p_m$$$, Bob will win. Bob will achieve this by making sure $$$m$$$ will never go to its sorted position. When $$$x=m$$$, Alice clearly can't change $$$m$$$'s position, and when Bob has to make a move, he moves to $$$p_m$$$ (i.e. the value currently in $$$m$$$'s spot). This move is always possible since every other vertex is adjacent to $$$m$$$.

          Otherwise either $$$m$$$ is already in its position, or $$$x \not\in \{m,p_m\}$$$, and Alice's first move is swapping $$$m$$$ into its position. In the latter case, let's make Alice's move and solve the resulting state (notice that in this case, $$$x$$$ will become $$$m$$$, since $$$x \neq m$$$ initially). Hence, we can assume $$$p_m=m$$$.

          Next, suppose initially $$$x=m$$$. We know that permutation graphs $$$i \rightarrow p_i$$$ form cycles, and that the number of cycles either increases or decreases by 1 with every swapping move (meaning their parity changes). Let the initial number of cycles of $$$p$$$ be $$$c$$$. Since we want to sort the permutation, we want the number of cycles to become $$$n$$$, so the parity of the number of swapping moves we must make is the same as that of $$$n-c$$$.

          Notice Bob's winning strategy when $$$n-c \equiv 0 \pmod 2$$$: no matter how many moves Alice makes, when she has 2 moves left to make, $$$x=m$$$ (every other move, $$$x$$$ will become $$$m$$$). Hence after Alice makes one of the two required swaps, Bob can simply move to one of the two values that aren't yet sorted, effectively preventing Alice from winning in the next move. Since Bob has such a blocking move whenever Alice is 1 swap away from sorting $$$p$$$, Alice can never win, so Bob wins.

          Otherwise, $$$n-c \equiv 1 \pmod 2$$$, in which case Alice has a winning strategy: whenever $$$x=m$$$, no move is blocked, so she can make an optimal move (one that increases $$$c$$$). Whenever $$$x \neq m$$$, the number of moves left is even, i.e. at least 2, so there are at least 3 values not in their positions yet, and regardless of where Bob is, there is an optimal move. Since Alice can always make an optimal move, she wins.

          So far we've assumed that initially $$$x=m$$$. When this isn't true, it will be true in the next move, but it does introduce one final corner case, which is only one move being required, and $$$x$$$ not covering either of the two values not in their positions, in which case Alice wins, even though the above parity cases would suggest Bob's victory.

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

Ratings updated preliminarily. We will remove cheaters and update the ratings again soon!

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

Fast rating, thanks.

I spent much longer on problem B than I should have, I came up with the idea pretty much instantly but messed up implementation many times. Does anyone know why my python solutions failed? I switched to c++ in the tail end of the contest and translated the same idea to solve B, since all my python solutions TLE'd.

This was my final python attempt, which I tried optimizing using bitwise operators:

https://codeforces.me/contest/1659/submission/153923577

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

    Instead of optimizing, you increased the complexity. You have a loop for i , and you are shifting i bits. shifting i bits take O(i) time. So your time complexity is O(n^2).

    Solution 1: store it in array and access each element in O(1) time. Solution 2: Instead of shifting i bits every time, notice that amount of bit shift changes by only 1. So you can use a temporary variable and divide it by 2 everytime.

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

Those who do Leetcode regularly, can you tell me is there also problems like todays B comes? Is todays problem B can be asked in big tech company Interviews?

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

My solution for Problem D.

We iterate from left the given numbers. If we hit some column with sum greater $$$0$$$, then we found a $$$1$$$ (marked with a rectangle in the picture. This is kind of an identifying $$$1$$$). We remove all $$$1$$$-s corresponding to the same color and accordingly adjust our array. Then we continue seeking for entries greater than $$$0$$$.

To find the corresponding column to a $$$1$$$ we just need to go as many steps forward, as we already found $$$1$$$s. See the bars at the bottom. The removing of the columns of $$$1$$$-s is simple. The removing of the diagonal of $$$1$$$-s can be either done with a lazy segment tree or by managing some variables about how much should be subtracted at the current position.

See my solution 153943020 in method "solve".

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

If you prefer command line, checkout CF Doctor for more flexibility and faster feedback.

If you are/were getting a WA/RE verdict on problems from this contest, you can get the smallest possible counter example for your submission on cfstress.com. To do that, click on the relevant problem's link below, add your submission ID, and edit the table (or edit compressed parameters) to increase/decrease the constraints.

If you are not able to find a counter example even after changing the parameters, reply to this thread (only till the next 7 days), with links to your submission and ticket(s).

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

Problem D sucks

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

A simple way to solve $$$D$$$:

Initialize all $$$ans[i]$$$ with ones. Now iterate on $$$i$$$ from $$$0$$$ to $$$N-1$$$. If $$$C[i]=0$$$, then $$$ans[i]=0$$$.

For every $$$C[i]\neq 0$$$, if $$$ans[i]=1$$$, we want to find the $$$0$$$ that will replace it at some move (if any), this should be the $$$C[i]^{th}$$$ element, so make $$$ans[C[i]]=0$$$.

Otherwise if $$$ans[i]=0$$$, then this should be replaced by a $$$1$$$ before it at some move, and then replaced by a $$$0$$$ after it (if any) at some move, so we want to find the $$$0$$$ that will replace it (if any), this should be the $$$(i+C[i])^{th}$$$ element, so make $$$ans[i+C[i]]=0$$$.

Submission

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

    Exactly how I thought about it, but my implementation(153950297) is a little weirder than yours.

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

    At the fourth paragraph in your idea (when $$$ans[i] = 0$$$) how do you arrive with the conclusion "... this should be the $$$(i + C[i])^{th}$$$ element" ?

    (i.e. where does the $$$i$$$ and $$$C[i]$$$ part comes from?)

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

      We have already maintained a $$$0$$$ at $$$i$$$ for $$$i-1$$$ moves. Now at the $$$i^{th}$$$ move, before making the move we have a $$$1$$$ at $$$i-1$$$, and after the move that $$$1$$$ will be at $$$i$$$.

      $$$C[i]$$$ tells us that a $$$1$$$ will be at $$$i$$$ for $$$C[i]$$$ moves. This means that that for the next $$$C[i]-1$$$ moves a $$$1$$$ is maintained at $$$i$$$. This means that at the $$$(i+C[i])^{th}$$$ move, the $$$i^{th}$$$ element will turn from $$$1$$$ to $$$0$$$, and since the only new element introduced at that move is the $$$(i+C[i])^{th}$$$ element, its value is for sure $$$0$$$.

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

        Hmm. Could you give an example for this argument ? I still don't quite get it :')

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

          For the binary string $$$[1, 0, 1, 0]$$$

          The sequences we get after each move:

          1. $$$[1, 0, 1, 0]$$$
          2. $$$[0, 1, 1, 0]$$$
          3. $$$[0, 1, 1, 0]$$$
          4. $$$[0, 0, 1, 1]$$$

          $$$C = [1, 2, 4, 1]$$$

          Consider the second position. It is first $$$0$$$, then changes to $$$1$$$ after the second move, and remains $$$1$$$ until the fourth move when it changes to $$$0$$$ again. Assuming $$$0$$$-based indexing, $$$C[1]$$$ tells us that the second element will be $$$1$$$ after the second and third move, then will be replaced by $$$0$$$ after the fourth move (obviously by the fourth element at $$$1+2=i+C[i]$$$).

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

    In third paragraph, "c[i]th element should be zero". I don't understand how is this sufficient.

    Actual condition should be: "C[i]th element should be zero and number of zeros before C[i]th element should be i". This additional condition is to make sure that C[i]th element actually replaces the ith element

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

Comparing Score distribution and problem difficulty was damn thug distinct .... A B C

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

Hi Mike please remove more cheaters I am at 1896

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

Thought solution not submitted and submitted second time and got penality as website stuck for few minutes and suddenly damn two times solution submitted (-50 points) :(

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

Time to practice A & B problems again. IS B a good problem? B ended my contest :v

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

24 hours for an editorial is quite poor, preparation really should be better...

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

How D?wtf????i think D is strictly harder than E

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

    Could you please tell me how to solve E

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

      Oh,I know how to solve it

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

      the ans will be 0/1/2,for 1 and 2 cant both exist (obviously).

      if you only go through edges with the edges that all have 1 is some bit(for example,go through 110 , 010 and 011 ,then the 1 in the second bit will persist,which means 0 wont exist), then the ans is 0.this case can be solved using ADT.you only have to check whether the u and v in each question is connected.

      what if the ans is 1?first,you should ensure that the ans mustnt be 0.second, mark the vertex that has an edge with an even weight from it with a tag "A".

      consider a question u and v,you dont want to get 1,and as long as you pass an edge with an even weight,you will never get 1 after that(you are safe now). so the problem is that before you reach any vertex with tag "A"(mentioned above),you dont want to get 1,and you will find it really similar to the problem we have already solved in para 2:make one of the bits always 1,except the lowest bit.also ADT and you will solve it easily.for every bit,find if in the component where u is exists a vertex with tag "A".for every question,if in some bit this is true then the ans can be 1.

      for the rest questions without an ans till now,the ans is 2.

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

    My sol of problem D:

    First, observe that the values of array only get permuted but not changed. So sum of c[i]s should be n*(number of 1s). Thus number of 1s can be calculated.

    Now you immediately know the sorted array of timestep n: 00..0011..11. And for former timesteps, The nth position is left unpermuted. Thus if c[n]>1, a[n]=1, otherwise a[n]=0.

    After that you remove the influence of timestep n from c[i]s, and repeat for timestep n-1,n-2,...,0.

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

Now I have a strange problem: after this contest, the rating change of the last contest Educational Codeforces Round 126 changed. And my rating before this contest is 2101. According to the rules, this contest should be unrated for me. How can I solve this problem?

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

When tutorial is available? Really confused about problem B. I feel I got the solution, but I couldn't pass test case2. Really want to know what's wrong in my submission.

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

Why does it happen sometimes that initially rating changes are applied, then they are rolled back and then again the same rating changes are applied? What happens when the rating changes are rolled back?

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

    Calculating rating changes depends obviously on the standings table of all partitipants. This means, if this table changes (i.e. because cheaters where removed), the rating changes also change.

    In a perfect world such recalculation would be one quick step, but it seems to be not trivial, so we see this "rollback" and "recalculation".

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

Will the copiers be banned?

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

I feel extremely happy that my idea works for problem B. 153975614

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

Contest difficulty >> expected.

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

"i_am_completely_useless for being completely useless." -- Sakura :))xD