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

Автор tokitsukaze, 23 месяца назад, По-английски

Hello, Codeforces! ฅ(*`ω´*)ฅ

We are glad to invite you to take part in Codeforces Round 789 (Div. 1) and Codeforces Round 789 (Div. 2), which will be held on May/08/2022 17:35 (Moscow time).

The round will be rated for all participants from both divisions. Participants in each division will be offered 6 problems and 2 hours to solve them. Both divisions will share 4 problems.

The problems were written and prepared by funer, dark_light, FreshP_0325, Frank_DD, qsmcgogo, winterzz1, Sugar_fan, TomiokapEace and me.

Thank to:

Here are some things I personally want to say. This is my second round. Three years have passed since the first round round 573 I held. Now I have graduated and worked. I like codeforces very much. Though I have already participated in work, haven't trained for a long time, my ability has degraded a lot, I will still come to codeforces to participate in the contest in my spare time. This time I also prepared some problems to propose a round, but for some reasons, most of them were rejected. In particular, one of my favorite problems was rejected because "many testers don't like it". I'm a little frustrated, but I also understand that the coordinator's job is to make the round better and more people like this round. I think it's a great honor to prepare round on codeforces and let so many people around the world try to solve the problem I prepared. I will accumulate some more interesting ideas for the next round and try to make more people like the problems I prepared.

I'd like to express my great gratitude to my friends for preparing this round with me, I don't think I can prepare this round alone without them. I really appreciate having the support of my good friends in my round.

In addition, the three naughty cats mentioned in the statement.(*=`ω´=)ノ I understand that I shouldn't post pictures irrelevant to the statement, so I post it here ↓

meow 0w0

Finally, I hope you like the problems in this round, good luck and have fun!(≧ω≦)/

The score distribution will soon be published.

UPD1: Although our coordinator allows to post the PDF of Chinese statements in the contest material, it seems that codeforces does not allow it. We are only allowed to post something after the round. So we will still post Chinese tutorials after the round.

UPD2: List of contributors is a bit changed, and the score distribution will be:

  • Div.2: 500 — (750 + 1000) — 1250 — 2000 — 2000 — 2750

  • Div.1: 500 — 1250 — 1250 — 2000 — 2500 — 3500

UPD3: Note that the score of the last problem of Div.1 has changed, 4000 → 3500.

UPD4: Editorial is out, and Chinese Tutorial will soon be published.

UPD5: Chinese Tutorial is out.

UPD6: Congratulations to the winners!

Div.1:

  1. maroonrk

  2. tourist

  3. eecs

  4. ainta

  5. duality

Div.2:

  1. NiNiV

  2. WA_On_Pretest2_Forces

  3. ouql

  4. KroosTheKeenGlint

  5. jialiang250

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

»
23 месяца назад, # |
Rev. 4   Проголосовать: нравится +25 Проголосовать: не нравится

Sofa~ Enjoy the round.(By the way, kitty lemon is so cuuute>w<).

  • »
    »
    23 месяца назад, # ^ |
    Rev. 2   Проголосовать: нравится +13 Проголосовать: не нравится

    Maybe only Chinese know what does “sofa” mean here(XD).In Chinese, “sofa” has the similar pronunciation to “the first one to post a comment”.

»
23 месяца назад, # |
  Проголосовать: нравится +2 Проголосовать: не нравится

sjfyyds!

»
23 месяца назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

sjfnb!!!

»
23 месяца назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

sjfnb!

»
23 месяца назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

Chinese statement!Wow

»
23 месяца назад, # |
  Проголосовать: нравится +38 Проголосовать: не нравится

So is this the first CF round contains Chinese statement? TBH in these recent days I'm also thinking about if it will be allowed to offer Chinese statement in my next round (if I will finish my problemset lol), and now surprisingly find your new round does it earlier.

  • »
    »
    23 месяца назад, # ^ |
      Проголосовать: нравится +21 Проголосовать: не нравится

    Our coordinator said he was told not to do this. Maybe the standard rules of codeforces round prohibit doing this kind of thing but we didn't notice it(

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

SJF YYDS!!!

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

I want to click on “Vote:I like it”,but I click on “Vote:I do not like it” by mistak。How can I change it? qvq

»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can't wait any more, let's enjoy sjf's round.

»
23 месяца назад, # |
  Проголосовать: нравится +62 Проголосовать: не нравится

So, what's the interesting chinese statements? Something like "Super Idol的笑容 都没你的甜 八月正午的阳光 都没你耀眼 热爱 105 °C的你 滴滴清纯的蒸馏水"?

»
23 месяца назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

A cat round. Excited to read the problem statements of the round.

〜( ̄▽ ̄〜)

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

    There is only one statement that mentions cats, so it probably doesn't count as a cat round =^•ω•^=

»
23 месяца назад, # |
  Проголосовать: нравится +13 Проголосовать: не нравится

I see meow, I upvote.

»
23 месяца назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

I hope this round came easier than the last one

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

≧ω≦ it is a nice cat .. I wish the round be good like the latest one ..

»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I'll have a cat sooner or later! QAQ

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

sjfnb!!!! I hope everyone can have fun solving our interesting problems ~ o(* ̄︶ ̄*)o

»
23 месяца назад, # |
  Проголосовать: нравится +9 Проголосовать: не нравится

sjf nb

»
23 месяца назад, # |
  Проголосовать: нравится +20 Проголосовать: не нравится

meow!

»
23 месяца назад, # |
  Проголосовать: нравится +39 Проголосовать: не нравится

to tell the truth the problems we discarded can make up another contest

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

Hope you can solve our interesting problems and gain high rating!

»
23 месяца назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

sjfnb!!!

»
23 месяца назад, # |
  Проголосовать: нравится +2 Проголосовать: не нравится
»
23 месяца назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

As the fourth naughty cat no one talks about I am absolutely hurt. iN oRdEr To compensate for tHiS mIsTaKe I mUsT bE gIvEn +200

»
23 месяца назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

When I first registered for this round, my rating was below 1900. Now, I've registered again for the same round but in Div. 1 category. Which category am I supposed to participate in now?

Can I make submissions in both categories during the contest ( ಠ◡ಠ )?

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

    You should cancel your registration for Div2, and even if you don't do it, Mike or other admins will remove participants in the wrong division before the contest.

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

sjfnb!

»
23 месяца назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится

I hope that i will be a pupil

Я надеюсь что я стану учеником

Good luck for everyone!!!

Всем удачи!!!

»
23 месяца назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится

I am curious about your favorite problem. As your favorite problem has got rejected, you can share it in chat

»
23 месяца назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Well, Chinese round, help me to be blue lol...

»
23 месяца назад, # |
  Проголосовать: нравится -35 Проголосовать: не нравится

So when are you eating your cats?

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

my first div1 contest :D

»
23 месяца назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

any one pls tell that what does it mean (750+1000) in scoring distribution Div.2: 500 — (750 + 1000) — 1250 — 2000 — 2000 — 2750 does it mean that 2nd question will be off 1750 orr it will of 750 or 1000 i'm bit confussed

»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

sjf nb!!!

»
23 месяца назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится

The cats look really tired after a long day of preparing the round.

»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

what actually that 750+1000 mean (in div 2 scoring distribution)

»
23 месяца назад, # |
  Проголосовать: нравится +55 Проголосовать: не нравится

Permutationforces again

»
23 месяца назад, # |
  Проголосовать: нравится +14 Проголосовать: не нравится

Problem C(div1) was really funny pretending to be a non-permutation problem.

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

    How do you assign the values to each independent cycle? Because that's what the problem is about right?

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

      $$$|a - b|$$$ is ultimately either $$$(a - b)$$$ or $$$(b - a)$$$.

      So, for each independent cycle, after opening $$$|.|$$$, some numbers would have a coefficient of $$$+1$$$, some would have a coefficient of $$$-1$$$ and some would have $$$0$$$ (as they'd have both $$$+$$$ and $$$-$$$).

      To maximize this, you'd need to take the largest possible values for $$$+1$$$ coefficient and smallest values for $$$-1$$$ coefficient.

      So, if cycle has $$$k$$$ elements, we can mark $$$k/2$$$ suffix elements as $$$+1$$$, $$$k/2$$$ prefix elements as $$$-1$$$ and depending upon whether $$$k$$$ is odd, we can mark the first unused prefix after all operations as $$$0$$$.

»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

server is tooo much fast guys :D

»
23 месяца назад, # |
  Проголосовать: нравится +13 Проголосовать: не нравится

The memory in problem C is very annoying

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

    Ya, like declaring 2 2-D arrays of O(5000^2) is giving runtime error !

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

    I really don't see what's the point of that restriction. I ended up spending ~5 more mins and also got an extra penalty.

»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Dang, that problem B though :P

I think it should be swapped with C (looking at point distribtuion)?

»
23 месяца назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится

Ugh! Headache from that B2 I'm done

»
23 месяца назад, # |
  Проголосовать: нравится -46 Проголосовать: не нравится

Solved 4 again including E . I wonder what would they say now . All they wanted was to bully me and downplay me

Context

  • »
    »
    23 месяца назад, # ^ |
    Rev. 4   Проголосовать: нравится +30 Проголосовать: не нравится

    B2 to E in 20 minutes. Uhhh what would we say? You cheated again? Don't worry buddy, if you failed to solve div3 a,b,c and a week later solved E (with 92 ACs in div2) in 20' you would be famous in India as a genius soon, and you would be known. Until then we all assume you are cheating.

»
23 месяца назад, # |
  Проголосовать: нравится +9 Проголосовать: не нравится

solved Problem C but didn't solve Problem B2 :(

»
23 месяца назад, # |
Rev. 2   Проголосовать: нравится +8 Проголосовать: не нравится

Finally solved a FFT problem during contest. POG

Edit: I just overcomplicated Div 1D like a bot. Ignore this comment

  • »
    »
    23 месяца назад, # ^ |
      Проголосовать: нравится -7 Проголосовать: не нравится

    what ?????

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

      Maybe Im just stupid but I used NTT to solve Div 1D.

      • »
        »
        »
        »
        23 месяца назад, # ^ |
          Проголосовать: нравится -12 Проголосовать: не нравится
        you can do it in O(n)???
  • »
    »
    23 месяца назад, # ^ |
      Проголосовать: нравится +23 Проголосовать: не нравится

    I did same :D. I was shocked seeing so many AC's so I thought a bit more later, and realized there was no need of FFT/NTT.

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

    FFT is a tool for (sometimes sneaky) polynomial manipulation. However, not every polynomial manipulation is FFT. If you can simplify until you work with pointwise multiplications instead of convolutions/inverses/etc, it's faster.

    I noticed the connection too, considered FFT but happened to write a solution without it.

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

    Apologies, my earlier comment might have come of as slightly rude because I did not know that you can solve the problem by thinking about the operations in reverse so I really curious how FFT appeared.

    Anyways, I just remembered that $$$n=10^6$$$ was the limit so I thought FFT couldn't pass since it was actually $$$O(n \log^2 n)$$$ even (I couldn't even get $$$O(n \log n)$$$ to pass 1548C - The Three Little Pigs when I tried it). I've hacked you with test like

    1
    1000000 0
    -1 -1 ...
    

    I've tried to hack Savior-of-Cross but his NTT imple too strong... 1886ms

    Edit:

    Thinking about how your solution and the solution in the editorial becomes the same, I have realized that your solution can be simplified to $$$O(n)$$$ without much difficulty. So you are calculating the polynomial $$$P(x)$$$ where $$$[x^i]P(x)$$$ is the number of final arrays with $$$i$$$ zeros in the range $$$[1,n-k]$$$.

    The number of initial arrays that can produce a final array is with $$$i$$$ zeros is $$$(k+1)^i \cdot k!$$$. Notice that taking the sum over all $$$i$$$ is same as finding $$$P(k+1) \cdot k!$$$ (we are evaluating $$$P$$$). We $$$P(k+1)$$$ without using NTT and solve in $$$O(n)$$$ using your method and this gives the exactly same calculation as the editorial

»
23 месяца назад, # |
  Проголосовать: нравится +17 Проголосовать: не нравится

Rubbish round

»
23 месяца назад, # |
  Проголосовать: нравится +14 Проголосовать: не нравится

C was easier than B2 :/

»
23 месяца назад, # |
Rev. 2   Проголосовать: нравится +15 Проголосовать: не нравится

Hints for Div2E/Div1C

Solve a simpler problem first. You are given $$$k$$$ boxes numbered from 1 to $$$k$$$. Assign unique values to them from the set $$$1, 2, 3, \dots n$$$ such that $$$\Sigma_{i = 1}^{k} |val[i] - val[i + 1]|$$$ is maximized.

Answer: 2*(Suffix sum of k//2 elements - prefix sum of k//2 elements).

Now, get rid of the 2 arrays to construct an array c where c[i] = index of b[i] in a[i].

Array $$$C$$$ is a permutation, and will have several disjoint cycles. The answer for each cycle can be computed from the formula above. In the end, we need to assign a sign, $$$+, -, 0$$$ to the array $$$[1, 2, \dots n]$$$. Each disjoint cycle would contribute cc_size/2 to the answer, for both the suffix and prefix.

»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

What was B2? Can someone provide me some testcases?

»
23 месяца назад, # |
  Проголосовать: нравится +51 Проголосовать: не нравится

Bruh, solution to E is somewhat tedious and straightforward, but requires you to solve "sum up the total area of rectangles in a rectangle" queries. I spent the whole contest implementing it. Seems to pass pretests, but since it is the only problem I submitted, maybe I shouldn't have submit it at all when I was done...

  • »
    »
    23 месяца назад, # ^ |
      Проголосовать: нравится +10 Проголосовать: не нравится

    My solution to E is: for each number, find its factorization (it is of $$$O(n \log n)$$$ for all numbers jointly) and also find closest numbers $$$L,R$$$ to the left and to the right of it that are larger than the number. Now let $$$i,j$$$ be the positions of $$$p_i \cdot p_j = p_k$$$ for the current number. Any segment $$$x,y$$$ such that

    $$$L < x \leq \min(i,j,k) < \max(i,j,k) \leq y < R$$$

    is valid. These equations define one of possible rectangles for allowed $$$(x,y)$$$ segments and your queries are like "find the area of the union of rectangles within a rectangle", which is doable with segment tree and sweepline in $$$O(n \log^2 n + q \log n)$$$ time overall.

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

      Can you elaborate a bit on how to "find the area of the union of rectangles within a rectangle" ?

  • »
    »
    23 месяца назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    You can also use a segment tree with range set to value and range historic sum. That data structure is pretty easy to implement.

    Basically, if the queries are $$$[a_i, b_i]$$$, loop over $$$b$$$ in increasing order, and maintain a segment tree such that at position $$$a$$$ we have a $$$1$$$ if the range $$$[a, b]$$$ is good, and $$$0$$$ otherwise. Then you can answer the queries with range historic sum queries.

    To maintain the segment tree, you maintain in a stack the current suffix maximums (ignoring all numbers in positions after $$$b$$$). When you pop the stack, set the corresponding range in the segment tree to 0.

    Next, you need to handle newly created pairs $$$i, j$$$ with $$$i \cdot j \leq n$$$. First, let $$$i = val[b]$$$ and loop over what $$$j$$$ is. If $$$i \cdot j = t$$$, $$$pos[t] < b$$$, and $$$t$$$ is the current suffix maximum in range $$$[x, y]$$$, set $$$[x, y] \cap [0, pos[j]]$$$ to $$$1$$$.

    Finally, if $$$val[b]$$$ is the maximum in range $$$[x, b]$$$, and $$$i, j$$$ is the pair satisfying $$$i \cdot j = val[b]$$$, $$$pos[i], pos[j] < b$$$ that maximises $$$z = \min(pos[i], pos[j])$$$, we set $$$[x, b] \cap [0, z]$$$ to $$$1$$$.

    Code: 156351162

»
23 месяца назад, # |
  Проголосовать: нравится +13 Проголосовать: не нравится

What's the solution for B2, is it something to do with dp?

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

    It can be solved without DP.

    Solution
»
23 месяца назад, # |
Rev. 3   Проголосовать: нравится -64 Проголосовать: не нравится

.

»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I want to know what's the intended solution for Div2C, cuz I just wasted 30 mins optimizing my original solution.

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

    O(n2) using prefix sum .I also used seg tree before O(n2logn) but got TLE.

  • »
    »
    23 месяца назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    Iterate over B and C, with B from the front and C from the back. Use 2 fenwick/segment tree to find # of numbers small than B and C on the prefix and suffix. Edit: AC Submission

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

    Let $$$D[i][j]$$$ be the count of pairs $$$(x, y)$$$, $$$x \leq i$$$ and $$$j \leq y$$$ such that $$$P_x > P_y$$$. This can be computed in $$$O(N^2)$$$ using dynamic programming.

    Then for each $$$a < b$$$ such that $$$P_a < P_b$$$, add $$$D[b - 1][b + 1] - D[a][b + 1]$$$ to the answer.

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

    The following thing works fine in terms of time: firstly for each $$$i$$$ and $$$m$$$ calculate $$$M(i, m)$$$ -- the number of elements of permutation, which are not greater than $$$m$$$ and have an index not greater than $$$i$$$, it's $$$O(n^2)$$$

    Then we can iterate for $$$b$$$ and $$$d$$$, but for each $$$d$$$ also remember $$$M(b-1, d)$$$, so if we find $$$d$$$ s.t. $$$p_d < p_b$$$, it will add to the answer sum $$$\sum\limits_{i=b+1}^{d-1} M(b-1, p_i) $$$. It's also $$$O(n^2)$$$

»
23 месяца назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

anyone pls tell me what was the intuition and how you've solved div2 2 (b harder version )

»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Permutation Forces

»
23 месяца назад, # |
  Проголосовать: нравится +15 Проголосовать: не нравится

Div 2 is too unbalanced

»
23 месяца назад, # |
  Проголосовать: нравится +62 Проголосовать: не нравится

Wow, I made the last "pretests passed" submission in the whole Div.1 round, at 01:59:46.

My heart was beating soooo fast!

»
23 месяца назад, # |
  Проголосовать: нравится +2 Проголосовать: не нравится

For me Div2 B2 >>> Div2 E

»
23 месяца назад, # |
  Проголосовать: нравится +263 Проголосовать: не нравится

F = this + this + this.

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

C was easier than B2 :/

»
23 месяца назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится

Would love to know the solution of B2.

»
23 месяца назад, # |
  Проголосовать: нравится +15 Проголосовать: не нравится

Solved B1 literally by "guessing" with no complete proof, feeling uncomfortable. Feel B2 could be solved by guessing also, but have no time to write it down. This is a bad experience. Really want to see clean solutions for B1 and B2 with PROOFs in the editorial.

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

    The solution in the editorial is indeed clean. During the contest I missed an observation and used a more complicated solution.

»
23 месяца назад, # |
Rev. 3   Проголосовать: нравится +7 Проголосовать: не нравится

Ordered set giving TLE in div2 C sed life :-(

»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

desperately waiting for the solution to B2

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

    Can B2 not be solved with 0-1 Knapsack? I feel like it is just the total number of segments — knapsack, but I could be wrong.

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

    If you solved B1, you should have noticed that you only apply operations to 01/10 pairs. We can think of the string as blocks of 2 successive characters. We can then solve the problem with DP. Let $$$dp[i][0/1]$$$ be the minimum number of segments if the current pair of successive characters is turned into $$$0$$$ or $$$1$$$. Then the transitions are: $$$dp[i][0] = min(dp[i - 2][0], dp[i - 2][1] + 1)$$$, $$$dp[i][1] = min(dp[i - 2][1], dp[i - 2][0] + 1)$$$.

  • »
    »
    23 месяца назад, # ^ |
    Rev. 6   Проголосовать: нравится +1 Проголосовать: не нравится

    if you have done B1 its obvious that a block of two elements should be same.Now lets consider a case 10101101010011. Here for first two elements it can be 11 or 00. for third and fourth element it can be again 11 or 00.So first four elemnts can be either 1100,0011,0000,1111.it is optimal to choose 1111 as the next two bits are 11.if the next two bits were 00,it was optimal to choose 0000.So we can say that if for a particular block, where first element == second elemnt==11,we can make previous all blocks of two elements like that particular block and can merge into one segment.But if a previous block found such that the block elements are 00,then we cant do anything but to count a new segment.but if a particular block found which is 11,then we can easily merge that too!

    more intuition : ------11----00----11 the dashed spaces represents blocks where first element != second element those spaces can be filled by 1 or 0.but the remaining 11,00,11 will not be changed as first element == second element. As dashed spaces can be formed by 0 or 1 the only thing deciding the segment whether there is a 00 infront of 11 or 11 infront of 00.

    So the answer is,for every i%2 ==0 check whether s[i+1]== s[i].if its true append the value of s[i]to an array.Now for every array[i] check whether array[i] != array[i+1].if its true ans will be increased by 1 as we have found a new segment

»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

My submission to pC

The time complexity should be O(n^2),but I got TLE. Can somebody help me?

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

    You are initializing a $$$5000 \times 5000$$$ array in every test case so your complexity is $$$O(t \cdot MAXN^2)$$$. You should use a vector instead. The same happened to my first submission. Imho this problem would be better off with single tests and a more generous ML.

»
23 месяца назад, # |
  Проголосовать: нравится +19 Проголосовать: не нравится

The funniest thing is how div1D was named "and permutations". Because the rest isn't :^)

»
23 месяца назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

1D is ezer than 1B and 1C !!!

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

Had to rewrite my solution to D2C from python to c++ because O(n*n*logn) with Fenwick wouldn't pass otherwise /:

Failed to solve B

»
23 месяца назад, # |
Rev. 6   Проголосовать: нравится +16 Проголосовать: не нравится

I think div2 C is easier than div2 B2. div2 B2 caused me to have no time to solve div2 D......

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

    It's obvious that it's intended, because B1+B2's score is 1750 while C's score is only 1250.

    • »
      »
      »
      23 месяца назад, # ^ |
      Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

      Well, B1 is very simple

      The actual time consumer is B2

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

        I don't think "B1 is very simple" unless the solution is clean with a complete proof of correctness. In particular, solving it using "intuitive guessing" is not clean. I would like to see a clean solution in the editorial.

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

        How do you solve B1? I spent a long time on it to prove greedy solution correct.

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

    That's why you should read all the problems and take scoring distributions with a grain of salt.

»
23 месяца назад, # |
  Проголосовать: нравится -7 Проголосовать: не нравится

I should have expected that it will be a trash contest from the blog vibes.

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

I think A is the hardest among first 5 problems in div 1.

»
23 месяца назад, # |
  Проголосовать: нравится +17 Проголосовать: не нравится

A is similar to 1400D - Zigzags

»
23 месяца назад, # |
  Проголосовать: нравится +18 Проголосовать: не нравится

How to write Tokitsukaze and Meeting without much pain? I had seen there several complex loops, and every time I tried to write them, I had gotten confusion.

»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

My solution for C with ordered set in C++ with O(n^2*logn) complexity was failing. Then i tried solution using 2 arrays in which space complexity was o(n^2) as well as the time complexity. It was giving MLE on test case 5. After optimizing the space for one of the arrays to O(N) the solution passed. I noticed someone else solution after the contest who had also used 2 arrays with o(n^2) complexity but used int than long long as I had done. Do data types affect space so much that a whole test case failed because of it?

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

    Using 32-bit instead of 64-bit ints roughly halves the memory requirement, which helps just as much as optimizing by using one array.

»
23 месяца назад, # |
Rev. 6   Проголосовать: нравится +11 Проголосовать: не нравится

I have a fun solution for DIV2 B1, pretty much different from other people's solutions :

Div 2 B1 solution
»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Is B2 DP?

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

    Yes, it's fairly standard dp once you notice that you only need to apply the operation to 01/10 pairs.

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

    I thought of 0-1 knapsack DP as soon as I read the problem statement, but I didn't see anyone using it. I can't figure out what's wrong with using knapsack?

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

    i solved it using DP

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

B1 and B2 can be solved with DP

states => i, parity of 0, parity of 1, last character parity

transitions try to make previous consecutive frequency even for any of the two elements at every recursion or just pass it with default values als note that at every point in recursion maintain either p1 == 1 or p0 == 1.

Solution

Code
»
23 месяца назад, # |
  Проголосовать: нравится +56 Проголосовать: не нравится

Fixed my bug on E 10 minutes after the contest, by just changing two chars. TaT

»
23 месяца назад, # |
  Проголосовать: нравится +116 Проголосовать: не нравится

Seriously, I've never seen a problem more stupid than Div.1 E.

»
23 месяца назад, # |
  Проголосовать: нравится +2 Проголосовать: не нравится

Man E is super easy. I think B1/B2 is harder than E. Why do we need to bring a super easy question like this to E?

»
23 месяца назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

My solution for $$$Div2$$$ $$$B$$$:

Easy part:

First observe that any valid solution consists of even ones, even zeros, even ones, ... So, any $$$prefix_i$$$ of odd length with $$$a[i]\neq a[i+1]$$$ will require at least one operation, the lower bound on number of operations is the count of such prefixes.

The mentioned lower bound is achievable, as such odd prefixes appear in the form of, e.g., even prefix followed by odd ones (odd prefix), even zeros (odd prefix), even ones(odd prefix), odd zeros (even prefix). So just changing the last value in each odd prefix will make all the prefixes where the values change to be even.

Hard part:

The objective here is to choose the values to change in a way to increase the connectivity of segments with the same value. From the previous proof, observe that any even $$$prefix_i$$$ ending with $$$2$$$ zeros or $$$2$$$ ones implies that in the final solution $$$prefix_i$$$ should end with the same value, otherwise more operations will be done.

So, we can greedily search for the next even prefix ending with $$$2$$$ zeros or $$$2$$$ ones and make the whole segment have the same value (starting from after the previous even prefix). When we cannot find any more such prefixes (reached the end of array), if the current segment we are working on starts from $$$i\neq 0$$$, we can choose $$$a[i-1]$$$ and use it in the whole segment, otherwise we can just choose any value.

Submission

»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

That balance is 10 out of 10 basically, but you've tried)

»
23 месяца назад, # |
  Проголосовать: нравится -21 Проголосовать: не нравится

Why C does not pass with Ordered_Set but applying Fenwick Tree it does?

I think such things should not happen in future either both should or both should not.

»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

This round let me feel that I sould give up

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

    Dude if you were specialist at one point that should let you know that you have at least some level of talent.

»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Thanks to the round authors for problem E, I liked it very very much. Unfortunately didn't have to implement it during the contest due to sucking too much at combinatorics >_>

»
23 месяца назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

for B1 just look at s[i] and s[i+1] if they are different then we have no choice other than to change any one of them.

for B2 just work in two length contiguious substrings if s[i] and s[i+1] are different then simply look at s[i-1] and make these equal. if s[0] and s[1] are different then once choose both of them 0,0 and find the values using above procedure, similarly for 1,1 and take the minimum of these two.

https://codeforces.com/contest/1678/standings/friends/true#

»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Waiting for usual YT editorials for last div2 problems :)

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

WTF!!

link this problem is the same as problem C I replaced every < by == and got accepted

»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

The pretests are so powerful that the issue occurred Runtime error on test 4 LOL

»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Problem C O(N*N*log) AC : 156339292

how is can fit when N up to 5000?

»
23 месяца назад, # |
  Проголосовать: нравится -27 Проголосовать: не нравится

Guys who created this round, what do you think about Winnie the Pooh?

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

As a Chinese,exicted for Chinese statement!

»
23 месяца назад, # |
  Проголосовать: нравится +34 Проголосовать: не нравится

It seems that I am the only person who FST on Div.1 B. :<

»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Здравсвтуйте, вы мне задачу C из Codeforces Round #789(Div. 2) засчитали как списанное, хотя если посмотреть в группе в которую вы меня занесли, мой код не имеет схожести с другими.

Мое решение : https://codeforces.com/contest/1678/submission/156348355

И несколько решений от пользователей из моей группы: https://codeforces.com/contest/1678/submission/156340778 https://codeforces.com/contest/1678/submission/156342693 https://codeforces.com/contest/1678/submission/156343315 https://codeforces.com/contest/1678/submission/156343329 https://codeforces.com/contest/1678/submission/156348676 https://codeforces.com/contest/1678/submission/156348782 https://codeforces.com/contest/1678/submission/156348723

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

Achievement unlocked: "Perfectly Balanced": obtain 0 delta

»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

A good contest!

»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

tourist научи прогать пж. Как выиграть IOI? Плиз туториал, заплачу 1р.

»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Thank you for the Chinese tutorial.