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

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

Hi!

On May/02/2021 17:35 (Moscow time), we will host Codeforces Global Round 14.

This is the second round of the 2021 series of Codeforces Global Rounds. The rounds are open and rated for everybody.

The prizes for this round:

  • 30 best participants get a t-shirt.
  • 20 t-shirts are randomly distributed among those with ranks between 31 and 500, inclusive.

The prizes for the 6-round series in 2021:

  • In each round top-100 participants get points according to the table.
  • The final result for each participant is equal to the sum of points he gets in the four rounds he placed the highest.
  • The best 20 participants over all series get sweatshirts and place certificates.

Thanks to XTX, which in 2021 supported the global rounds initiative!

All problems were written and prepared by me FieryPhoenix and dragonslayerintraining.

Huge thank you to everyone who made this round possible:

You will have 3 hours to solve 9 problems. Scientific studies have shown irrefutable evidence that upvoting this blog and participating in this round will lead to longevity and happiness. GLHF!

UPD: The scoring distribution is 500 — 1000 — 1500 — 2000 — 2750 — 3250 — 3500 — 4250 — 5000

UPD: Editorial is here!

UPD: Congratulations to the winners!!

  1. Radewoosh
  2. ksun48
  3. Um_nik
  4. Benq
  5. yhx-12243
  6. tourist
  7. duality
  8. jiangly
  9. LJC00118
  10. NotaMotuaQAQ
  • Проголосовать: нравится
  • +1595
  • Проголосовать: не нравится

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

Is it rated?

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

For anyone wondering what GLHF (in the last line) means — Good Luck, Have Fun!

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

ugh i cant make good meme : (

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

PurpleCrayon orz!

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

Scientific studies have shown Global Round are usually hard, but I will participate for longevity and happiness.

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

As I tester of this round people are giving me downvotes.

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

As a tester, there's a reason this round is a Global Round (cf's flagship contest). The statements are natural and concise, the problems are elegant, and I hope you have a great round!

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

sto PurpleCrayon orz

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

Relatable >_<
original meme

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

omg, a round prepared by the Americans with Chinese names

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

Global Rounds always provides a very good opportunity to boost up your rating... Excited!!!!

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

    And a very good opportunity to boost it down, too =)

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

    lol no. for the same performance you get much more rating in div2 than in global/div1. Not that it should matter but that's not the point here.

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

      It may vary from individual to individual depending on the topics in the round for example.
      However in general for the same performance you get the same rating. That's the whole point of ELO.

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

        Nah

        I can barely get any positive delta if I solve A,B,C in Div.1, whereas in Div.2 Solving up to E once made my rating go as high as 2255.

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

          Nah

          First, from your history, you never ever solved A-B-C in div.1 only rounds, so I don't quite get what you're talking about

          Also when you got your 2255, you had rank 8, there were only seven "violets" who performed better. Just compare it to your performance in div.1 rounds

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

        ELO system is not perfect. It makes very simplistic assumptions about the estimated probability of one player beating the other, based on just a single number (player's rating score). My understanding is that if rating scores of players are very far apart, then ELO based predictions become much less accurate. And isn't this the primary reason why division based restrictions exist?

        Anyway, all of this can be probably confirmed or debunked by just re-calculating rating score updates of div.2 contests without filtering out the normally non-rated people with 2100+ rating. My guess is that it would be a bad news for the rating scores of weaker participants. But of course I may be wrong.

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

    I have observed there's a lot more cheating in global rounds than normal rounds. Honest participants usually suffer in global rounds imo.

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

      Most probably because it's of 3hrs and cheaters get sufficient time to cheat .

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

As a tester, unfortunately, I don't have any witty joke to write in this message.

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

Can't we participate from m1.codeforces.com or m2 or m3? I couldn't find this contest on any of these versions of codeforces.

UPD: Its added. Thanks.

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

Nice

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

Omg 5000 points for a problem. Focus on the last problem, problem I with 5000 points, that's enough. :D

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

Contest time is really bad

Why aren't contests more late or earlier (for example 15:35 or 21:35)

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

Are the two contest authors related?

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

What is ORZ, I've seen it in many comments.

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

Me, a football lover coder today

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

This round has extremely strong pretests.

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

First contest in isolation! I hope I have the energy to compete. #COVID_coders

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

    Same here brother, me too suffering from covid, I can feel your pain. T_T :(

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

    Same situation. Tested positive yesterday. Unlike others I am having a headache, so decided to take some rest.

    If you are not well, I advise you to do the same.

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

Scientific studies have shown irrefutable evidence that upvoting this blog and participating in this round will lead to longevity and happiness

1000 people : wow we will upvote!

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

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

    Hmmm, I was imagining a closet full of segment trees, linked lists and a few queues. Never thought of the struct t_shirt. Hmmm..

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

PurpleCrayon orz!!!!!!

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

wer retin chains ?

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

Is it only me who can't do anything for 1 hour before the contest and keep switching between different tabs until it starts?

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

    Maybe you have to do the same thing after 2 hrs in this contest(considering the difficulty of global round).

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

There is a long queue, about 4 pages show only "running". Would that affect the round?

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

My first Global Round,nervous.

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

My rating after this global round going down like Wheeeeeeeeee

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

I upvoted the blog and participated. I guess the scientific studies and their evidences for longevity and happiness are wrong :(

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

I wonder if D is that easy felt like a normal C

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

    I worked like two hours on d but didnt get it :/

    • »
      »
      »
      4 года назад, # ^ |
      Rev. 3   Проголосовать: нравится -8 Проголосовать: не нравится

      And I worked two hours on C

      xD

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

      it happens sometimes i can't solve an A problem even so more like 11000 solved it that's weird and I thought so hard and still didn't get it XD

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

        Yeah man, your rating graph and game is truly inspirational! (y)

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

          it will be better trust me I had a hard time and couldn't learn anything new for like 2 years and a half but now things really changed

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

            I feel your pain in these comments. Whatever the hard time you had I am sorry for that. Your consistency is brilliant. I hope God gives you the power to battle these hard times and you learn new things and reach the master level or so.

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

      Well here's what i did for pretests(don't know if it will pass or not)-

      if $$$l==r$$$ then count how many numbers are same in both $$$l$$$ array and $$$r$$$ array call this count and answer would be $$$ans = r - count$$$

      if $$$l!=r$$$ then we are sure we need to shift $$$abs(l-r)/2$$$ elements from larger array to smaller array to make size equal, add it into the ans and now before shifting we will first remove those numbers from both the arrays which are same (as shifting them would cost an additional money to change the color) after this we shift those elements from larger array first that are similar to each other so that 1 copy of that element stays in larger array and 1 copy in smaller array and we don't need to spend additional money to change the color, even after this if elements are not same we will change their color and add it into the answer.

      consider this-
      14 10 4
      1 1 1 1 2 2 2 2 3 4
      1 1 1 1
      we will first remove all the ones as they are present both in $$$l$$$ and $$$r$$$ arrays, after this its better to remove two 2s from $$$l$$$ as it will prevent us from spending extra money on them by changing color now the arrays would become-
      1 1 1 1 2 2 3 4
      1 1 1 1 2 2
      now we just shift either 3 and 4 and also change its color.

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

D is not even close to 2000 score

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

lol, how to do well in global round? Weirdly I perform badly whenever I participate in global round(somewhat not bad in other Div. 1 + Div. 2 round).

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

Once again C was much tougher than D to me

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

How to solve E? I can only come up with $$$O(n^4)$$$ $$$dp[i][j] =$$$ ways to turn on $$$i$$$ computers with $$$j$$$ operations used

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

    And it can pass the pretest.

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

    Note that there cannot be more than one consecutive light that turns on automatically. So, our final answer will have some segments of $$$1$$$'s (lights that are turned on manually) separated by exactly one $$$0$$$ (lights that are turned on automatically). We need to find the number of ways to make such an arrangement.

    Let's take this one step at a time.

    In how many ways can we turn all the lights on manually?

    You can only choose one starting light in a segment of n lights, then at each step you can either go left or go right. For better visualisation, consider n points coloured red. Pick a starting point and colour it blue. In each step, you can move from a blue point to an adjacent red point.

    Number of ways to do this = $$$(L + R)! / (L! * R!)$$$ , where L is the number of steps to the left of the starting point that one can take, and similarly, R is to the right.

    To meet the constraints, we will be precomputing these answers till $$$n$$$.

    Now, coming to the main solution.

    Let $$$dp[i][j]$$$ = number of ways we can arrange the first $$$i$$$ lights such that the $$$i$$$ $$$th$$$ light is manually turned on and a total of $$$j$$$ lights were turned on automatically among the first $$$i$$$ lights.

    Let $$$k...i$$$ be the last segment of $$$1$$$'s. This means that at position $$$k-1$$$ we will have a $$$0$$$ and at position $$$k-2$$$ there will be a $$$1$$$. If there are exactly $$$j$$$ $$$zeros$$$ in the segment $$$1...i$$$ then there are exactly $$$j - 1$$$ $$$0$$$s in the segment $$$1...k-2$$$.

    Let's define an operation, as we turning a light manually on (or placing a $$$1$$$). So in the segment $$$1...k-2$$$ we have to place $$$k - 2 - (j - 1)$$$ ones, and in the segment $$$k...i$$$ we have to place all $$$i - k + 1$$$ ones. This is similar to the question we answered above for placing all ones. We have to tell the number of permutations of $$$(L + R)$$$ items, in which the order of the $$$L$$$ items and $$$R$$$ items are fixed.

    Therefore, the ans for $$$dp[i][j] = dp[k - 1][j - 1] * nCr((k - 2 - (j - 1)) + (i - k + 1), (i - k + 1)) * ways$$$ $$$to$$$ $$$arrange$$$ $$$(i - k + 1)$$$ $$$ones$$$

    PS: I know it's a little too verbose. But hope you can understand the solution.

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

    You can simply let computer $$$i$$$ in $$$dp[i][j]$$$ be turned on automatically.

    so you just have to enumerate the last automatically turned on computer before computer $$$i$$$ for $$$dp[i][j]$$$

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

How to solve D?

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

How to solve B and C ?

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

    For b check the if number is divisible of 2 or 4 and the remaining number should be a square number.

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

    In C, keep assigning the block to the tower with minimum current height. Can be done using set <pair<int, int > >. Also the answer can never be NO,

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

      How to justify this solution i.e how to prove that difference in height won't exceed x ?

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

        Suppose we have formed m blocks(B1,B2...Bm) with some i(i<n) smallest height towers.

        h[B1] < h[B2] < .... h[Bm] and h[Bm] — h[B1] <= x

        now h[i+1] can at max be x, So, if we add it to B1 then abs(h[i+1]+h[B1]-h[Bm]) <= x. So our condition holds always.

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

          Nice prove. thanks. Can you share your thought process for solving this ? Like how you approached this problem before coming to final solution ?

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

            Initially i just tried random greedy strategies but got WA. Then i thought of somehow using the fact that each height < x and tried proving a greedy approach.

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

        As every height is <=x as mentioned in the question and also we are filling blocks in sorted order of their heights, the maximum height between 2 stacks will always be atmost 1(because we are filling all the m stacks each with a block and start the next iteration).

        So, as the size difference between stacks is atmost 1. The difference between the stacks will always be the block which we are keeping at the top as it was mentioned each block is having height <=x filling this way will always give our answer.

        Hope this helps :) Please correct me if there are any mistakes.

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

    For C, just sort by block lengths and assign to each stack.

    For B, divide by 2 and 4, and see if number is a square.

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

    B — If I don't FST, if dividing by 2 or 4 gives you a square (number) its a yes C — no idea I kept WAing

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

    Assuming that I will not fail system tests.

    Problem B: Notice that we can only form squares using 2 or 4 isosceles triangles. So just check if the given number of triangles is divisible by 2. If it is, then check if (n/2) is a perfect square. (We can form a square of size sqrt(n) considering 2 triangles as a single block). Now, if this fails then check if n is divisible by 4. If it is, then repeat the process above. The answer in any other case is NO.

    Problem C: I have done this greedily. Using a priority queue, I always select the tower with minimum height and add the blocks in decreasing order after sorting. After adding all the blocks, I check if the difference between the minimum and maximum height is smaller than or equal to x.

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

how to solve problem D?

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +5 Проголосовать: не нравится
    • Remove all the already matching pairs as they do not affect the overall answer.

    • Now, check if number of left socks = number of right socks, then the answer is simply the number of left socks (this happens because we have already removed matching socks and hence we can just change the color of socks from any one leg to match it with the other leg)

    • Now, we know that we have to transfer some socks from one leg to the other.

      • Observation: It is always better to transfer socks which form a pair.
      • Example: Consider we have Left: 2 2 1 3 Right: 4 5 Now, we know that we have to transfer one sock from Left to Right, and it will be best if we transfer sock 2 from left to right, as it then forms a pair with the one sock 2 which would remain in left.
    • Now, after transferring greedily, we again remove the matching pairs of socks in left and right. Now, if the remaining number of socks in left and right are same, then the answer is simply number of transfers we made + number of left socks (we change the color to match the right socks as we already have removed the pairs). If the number of socks are still not the same, then we can simply transfer any socks from the pile having greater number of socks to the other and then change the colour of the remaining socks. In this case, the answer becomes the number of transfers we made earlier(greedily) + greater pile size.

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

How to solve E ???

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

Lets hope the pretests for F are strong :)

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

how to solve problem no D?

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

How to solve F orz... I try to merge two nodes $$$u$$$ and $$$v$$$ which $$$a[u] + a[v]$$$ is maximum.

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

    As long as initially $$$\sum_i a[i] \geq (n-1) x$$$ and the graph is connected, there is always a road you can build, no matter which roads you build and in which order. This means you can discard all edges but some $$$n-1$$$ that form a tree.

    Then, start doing arbitrary possible operations. Maintain in every component the values $$$a[j]$$$ for the components $$$j$$$ of children of the component, and in a priority queue the maximum current value $$$a[i] + a[j]$$$ over pairs (component $$$i$$$, component of child of $$$i$$$).

    Complexity is $$$\mathcal{O}(n \log^2 n)$$$ with small-to-large merges.

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

Did anyone get an FFT solution to pass for E? I'm having a rough time getting my code faster than 5 seconds sadly...

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

    what is the FFT solution?

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

      So we're going to work with ranges of computers that are off. Let $$$dp[k, t, end]$$$ be the number of ways to turn on a segment of length $$$k$$$ when toggling exactly $$$t$$$ computers, with $$$end = 1$$$ if the left end of the segment is the end of the whole array and $$$0$$$ otherwise (the only time both ends are the ends of the array is when $$$k = n$$$, which we case out). We assume that the right end of the segment is always adjacent to a computer that is already on Then our transition is

      $$$\displaystyle dp[k, t, end] = \sum_{i=0}^{k-1} \sum_{j=0}^{t - 1} \binom{t - 1}{j} dp[i, j, end] \cdot dp[k - 1 - i, t - 1 - j, 0]. $$$

      Basically, we are choosing to toggle the $$$i+1$$$th computer, splitting our segment into two. The lengths of these segments are $$$i$$$ and $$$k - 1 - i$$$ respectively, and we allocate these segments $$$j$$$ and $$$t - 1 - j$$$ toggles respectively. Then, for the remaining $$$t - 1$$$ toggles that we have, we choose $$$j$$$ of them to use on the left size, and $$$t - 1 - j$$$ of them on the right side. We can rewrite this as

      $$$\displaystyle dp[k, t, end] = \sum_{i=0}^{k-1} \sum_{t_L + t_R = t - 1} (t-1)! \frac{dp[i, t_L, end]}{t_L!} \cdot \frac{dp[k - 1 - i, t_R, 0]}{t_R!}, $$$

      which we can optimize to a convolution as follows: let $$$dp[k, end]$$$ be a polynomial in $$$x$$$, where the coefficient of $$$x^t$$$ is the value of $$$\displaystyle \frac{dp[k, t, end]}{t!}$$$ (our old DP). Let's fix some $$$k$$$ and $$$end$$$. Let $$$p(i)$$$ be the polynomial

      $$$p(i) = dp[i, end] \cdot dp[k - 1 - i, 0],$$$

      and let $p(i)[t]$ denote the coefficient of $$$x^t$$$ in $$$p(i)$$$. Then, we make a new polynomial $$$q(i)$$$ (I know my naming is getting egregious), with

      $$$ q(i)[t] = p(i)[t] \cdot t!, $$$

      i.e. we multiply the coefficient of $$$x^t$$$ in $$$p$$$ by $$$t!$$$. Then, we let $$$r$$$ be the polynomial

      $$$\displaystyle r = x \sum_{i=0}^{k-1} q(i). $$$

      Then, the coefficient of $$$x^t$$$ in $$$dp[k, end]$$$ is exactly

      $$$\displaystyle \frac{r[t]}{t!}. $$$

      The overall runtime is $$$O(n^3 \log n)$$$. I think there's a way to further optimize this by doing some 2D convolution, but I don't really know how to do anything like that (or if it's even possible). The idea for all of this is based on generating functions, but I'm not very well versed with those either, so maybe some trick from those can be useful here.

      Here's my code: 114957402. It runs in about $$$5.5s$$$ locally, and with some annoying optimizations I've gotten it a bit further down, but not by much.

      update: I got it to pass (114970160) with some optimizations + pragmas

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

    No need for FFT. You work with segments of manually toggled computers, with single automatically toggled ones in between. Then DP states are (first $$$i$$$ computers toggled, the last one is automatic or right endpoint of a segment, number of manually toggled computers up to computer $$$i$$$), and there are just $$$O(N^3)$$$ state transitions.

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

      Can you explain the transitions? i might not solve it on my own.

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

        If the $$$r$$$-th computer is the right end of a segment (so $$$r+1$$$ would be automatically toggled or $$$r=N$$$) and the $$$l$$$-th is its left endpoint, then $$$dp_{l-1,k} \rightarrow dp_{r,k+r-l+1}$$$ for each $$$k$$$ (number of manually toggled computers before $$$l$$$).

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

    You can solve this task without FFT.

    We can see on array as blocks set of consecutive computers.

    Let write the 1st DP f[len][cnt] — answer for on first len computers, where cnt computers we turned on themselves. Calculating DP looks like f[len + bs + 1][cnt + bs] += f[len][cnt] * fullblock[bs] * C[cnt + bs][bs], where fullblock[bs] — number of permutations for turned on by hand bs computers among bs computers.

    For fullblock[bs] we need in the 2nd DP. dp[len][last_pos][flag] — number of permutations with len computers, there is computer with index len stay in position last_pos, flag = 0 when position of index len — 1 stay to the left of last_pos

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

Phoenix Played with all of us

»
4 года назад, # |
  Проголосовать: нравится +43 Проголосовать: не нравится
»
4 года назад, # |
  Проголосовать: нравится -47 Проголосовать: не нравится

shitiest ABCD. also the scoring distribution was bullshit. 2000 fucking points for D :\

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

    damn, you have crazy expectations for problems..

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

      No,u just set them very poor and there is no wrong in accepting that. Problem D is not supposed to be solved by 4.5k people. Thats just dumb problem

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

        Then why did you spend almost 2 hours on it and get it done only from a 7th try?

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

        The first comparison criteria among the participants is the number of problems they solve, second is the time they spend on each problem and the amount of penalty they receive, easier problems may fade the impact of the first criteria but the second still stands and that's what makes you one of the worst second division participants of this contest.

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

      It was a good contest dont let them tell u otherwise!![user:FieryPhoenix]

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

    Very shit contest for div2 participaants indeed (seeing most of them usually do upto D). Stupid problems, just stupid

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

I wonder that if there is a contest without graph theory problems......

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

hmm how F checker works?

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

    It uses union-find to track connected components of the graph, augmented with the amount of asphalt in each component (stored at the roots of the union-find data structure).

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

How to solve E ?

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

    I used dp to find all the possible combinations of switches that we manually turn on. For example, X_XXXX_XX_X, XX_X_X are some valid sequences. The gaps represent switches that automatically are on. It is easy to see that the size on contiguos gaps will be atmost 1.

    Now, for each such combination we've to find the number of permutations to fill the X's. To do that I used 2 more states, {position, continuos X's till pos, number of skips}. I use skips to calculate how many were manually ONed before the contiguos Xs until pos.

    Now another important thing to note is that, The number of permutations to arrange r numbers such that theres no gap between them is 2^(r-1). (Try to prove it)

    After that we just have to use some more combinatorics to combine 2 contiguous segments of X's in our dp. There will only be 2 transitions, pos->pos+1 and pos->pos+2 (skip->skip+1). Rest of the details should be clear in my code

    Submission

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

I am getting Memory Limit Exceeded using multisets in problem D. Please have a look at my code: https://mirror.codeforces.com/contest/1515/submission/114956539

Why using map instead of multiset do not give this error?

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

mgmggmgm greedies and observations go brr

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

WA on pretest 3 on problem D again and again.

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

Pending System Testing for everyone?

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

Passed samples of problem E just before the end of the contest, submitted it and got a MEMORY_LIMIT_EXCEEDED on test 1. And there's not enough time to fix it. :(

The retribution of bad habits comes.

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

rainboy orz.

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

There is something called greedy algorithms, Problem D was based on ultra greedy Algorithm.

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

A to D seemed doable but still I was only able to get A correct, looking forward to editorials to understand the missing cases.

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

Idea for E?

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

The setters wanted to emphasize "Problem C uses constructive algorithms" (Some other problems also have two same tags)

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

A-D weren't very pretty problems but weren't too bad either. I liked E though.

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

In case you're curious about B: it should be obvious that since the sides of triangles are $$$1$$$ and $$$\sqrt{2}$$$, the side of the resulting square has to be $$$a+\sqrt{2}b$$$. Then, the area is $$$N/2 = a^2+2b^2+\sqrt{8}ab$$$, but since $$$a,b$$$ are rational, $$$\sqrt{8}ab$$$ can be a rational number only if $$$ab = 0$$$. That means $$$N/2 = a^2$$$ or $$$N/2 = 2b^2$$$.

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

Thank you setters for a very shitty round. Enjoyed every inch of it. Please dont make such shit problems in the future

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

    Stop bullshitting everywhere. Contest was good, maybe your ass got burned with D. So keep your shitty opinions to yourself, ultrashitposter.

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

      Ok, I agree that its my rage but I dont get how a person who didnt even do the contest live is giving feedback.

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

        I wrote from my other account and solved A-D.(I just created that a week ago to see how I performed if I started anew). You can verify in the discord server if youdoubt me, I already discussed it there.https://discord.gg/5DCnEpbB

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

          Well, first of all alting is against the rules, better wish mike doesnt read it message lol.

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

            Your account seems alt also,why don't you have your name, country name in your account. So go on and sue me .

            • »
              »
              »
              »
              »
              »
              »
              4 года назад, # ^ |
                Проголосовать: нравится -8 Проголосовать: не нравится
              Hope this might help
              • »
                »
                »
                »
                »
                »
                »
                »
                4 года назад, # ^ |
                  Проголосовать: нравится +2 Проголосовать: не нравится

                Yeah, glad I was able to help you, keep extending that help to others.

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

Wow, such a balanced contest

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

link to solution.

Can someone tell me why this code is failing even for the first pretest for problem C. It is running fine in my local.

Any help would be very very much appreciated. Thanks in advance.

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

I'm in love with my solution to I, so I'll share it in case it's different from the model solution:

Ofc. let's sort the diamonds by the order we we'll pick them, the leftmost item is the first to pick. Let's define $$$f(x)$$$ as the maximum integer $$$k$$$, such that $$$2^k \leq x$$$.

Let's build the segment tree on the sequence of diamonds and for each query of the third type let's run dfs on it. Ofc. in leaves we can normally consider the diamonds, but it would be too slow, so we are looking for a speedup. Let's split into two smaller segments each time when $$$f(size~of~our~backpack)$$$ will decrease somewhere in it. If it won't change, then let's do something smart to skip the whole segment in $$$O(1)$$$.

When will it decrease? It'll happen for sure if in the segment that we currently are is some diamond with weight $$$w$$$, such that $$$f(w) = f(size~of~our~backpack)$$$ and $$$w \leq size~of~our~backpack$$$. It will happen also if the sum of the weights of all diamonds with $$$f(weight) < f(size~of~our~backpack)$$$ is at least $$$size~of~our~backpack$$$. In these two cases let's just solve the segments recursively. If neither of the conditions hold, we know that we'll simply take all the diamonds with $$$f(weight) < f(size~of~our~backpack)$$$.

Final observation: $$$f(size~of~our~backpack)$$$ will decrease at most $$$\log$$$ times and for each time it decreases we we'll do only $$$O(\log(n))$$$ splits, so the complexity for each query will be $$$O(\log^2)$$$. Let's then build $$$O(\log)$$$ segment trees. Each of them will keep the minimum weight of a diamond with $$$f(weight) = id~of~tree$$$ and the sum of weights and values of diamonds with $$$f(weight) \leq id~of~tree$$$. We can modify these values in $$$O(\log^2)$$$ per query and the query about finding the score also can be done in $$$O(\log^2)$$$ then.

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

Thanks for the contest! The problems I read were all pretty nice. I'm a bit salty that I failed E and didn't think of working on F instead but that's part of the CP experience :)

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

WTH is wrong with this solution for B??? Input can't exceed 1e9, what am I missing and why does it fail test 5?

code

EDIT: Fuck me, I'm dumb.

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

    Isn't it because your set s will contain numbers up to only $$$10^6$$$ instead of $$$10^9$$$?

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

fuck u motherfuckers, it was the most bullshit global contest ever. please dont let this son of the bitches make contest, MIKE.

  • »
    »
    4 года назад, # ^ |
    Rev. 2   Проголосовать: нравится -109 Проголосовать: не нравится

    fuck u motherfuckers, it was the most bullshit global contest ever. please dont let this son of the bitches make contest, MIKE.

    Update: This was a poor attempt at starting a copypasta designed to make fun of the original comment. I didn't even participate in the contest and I liked the problems.

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

      Ok then why don't you become master and show everyone how to set contests ಠ_ʖಠ

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

(╥﹏╥)

Pics-Art-05-03-12-20-01

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

When you fix the bug(1 char bug)in your code 15 seconds before the contest end and then your internet decides to load the page very slowly and you miss submitting the problem by 1 second.(It turns out it took me less than a minute to ac in upsolving :( now I will lose rating instead of becoming IGM)The bug was that I used variable xx instead of x at place

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

no brain me solving question A by shuffling the array multiple times codeforces: we wont let u cry this time, Accepted

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

To not keep you waiting, the ratings updated preliminarily. In a few hours, I will remove cheaters and update the ratings again!

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

tfw OEIS doesn't work

  • »
    »
    4 года назад, # ^ |
    Rev. 3   Проголосовать: нравится +38 Проголосовать: не нравится
    might be the reason
  • »
    »
    4 года назад, # ^ |
    Rev. 2   Проголосовать: нравится +6 Проголосовать: не нравится

    I coded up a brute force solution and generated the answer for N up to 20. Plugged that into OEIS. Nope lol.

    I have no idea why I even tried. Great job problem authors! It's your win this time :D

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

Why system testing is happening again?

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

Today's global was the coolest of all that I handed in. Thank you very much FieryPhoenix ! I will wait for more competitions from you

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

Great contest! (and thanks for the IGM)

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

https://mirror.codeforces.com/contest/1515/submission/114966463 why does this give tle on b problem? plz explain its sqrt(n) only.

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

    sqrt(n) can be found in O(logn). You have written O($$$\sqrt{n}$$$) logic

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

      Editorial has mentioned sqrtn solution also..

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

        It has mentioned that it is possible to write an O($$$\sqrt{n}$$$) solution, not that it will be AC. For $$${10^4}$$$ test cases with $$$\sqrt{10^9}$$$ complexity, your solution won't pass the time limit.

        EDIT: I don't get why the comment is getting downvotes. I still stand by my statement, O($$${10^{8.5}}$$$) should not get an AC.

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

    The problem is the line #define int long long int. Computation and I/O is more costly for long long integers and so, often the overhead in such cases causes a TLE.

    I just commented out that line and it got accepted.

    114980681

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

somebody please explain why i am getting wrong answer in test 3 in D here's my submission https://mirror.codeforces.com/contest/1515/submission/114967116

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

114951091 Don't know why getting Wrong Answer. Can somebody find a testcase which gives wrong answer to the code.

How the answer in following test case is 3 and not 4

10 6 4

4 5 3 5 8 5 5 10 10 4

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

    With initial socks $$$[4, 5, 3, 5, 8, 5]$$$ and $$$[5, 10, 10, 4]$$$,

    1. Change one $$$5$$$ from left to right to get $$$[4, 5, 3, 5, 8]$$$ and $$$[\color{red}{5}, 5, 10, 10, 4]$$$.
    2. Now there are equal number of left and right socks. Only two pairs of socks have different colors, so we can change these two socks: $$$[4, 5, \color{orange}{10}, 5, \color{orange}{10}]$$$, $$$[5, 5, 10, 10, 4]$$$.
»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

can anyone kindly explain why greedily adding the 2 smallest values in the array not work in c.

like if we have [2,4,7,9,10] and if we want 3 block just add the smallest 2 and replace, by this we get [6,7,9,10] and then again do the same thing, thus getting [13,9,10] the max difference is 4 which is okay, if we were to do any further operation we would have done that to 9,10

but this gives WA, can anyone suggest a counter example

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

    Here's a test case that fails your code:

    1
    8 3 1
    1 1 1 1 1 1 1 1
    

    The towers produced by your code have heights $$$4$$$, $$$2$$$, and $$$2$$$.

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

      wow thanks, couldn`t figure out why the above algo didnt worked and hence struggled in the contest too. is there any way to find countertest to your algorithm or just you have to think about it for long

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

        I just tested with many tests until I found one that is not correct. Since your idea seems correct, I suspected that it was probably wrong on some kind of special cases.

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

someone please explain why i am getting wrong answer in test 4 in D . my submission: 114958100

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

Commenting this again because did not get any response in the previous comment.

Solution

Can someone explain why this solution for problem C is failing even for the first pretest. It works fine in my local machine.

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

    you're not iterating through the whole vector, missing i = m. So, one value you're getting is just garbage value.

    Also, you might have to sort it in descending to work.

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

Здравствуйте. Может кто подскажет почему такое.

По итогам Global Round 14 почему-то неправильно пересчитан мой график. В нем показывает, что я занял 3747 место и -80 к рейтингу, тогда как в самой таблице у меня вполне неплохое по моим меркам 1307 место. Где-то здесь баг — либо все-таки какая-то моя задача упала на системном тестировании, либо в отображении графика какой-то перекос.

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

Got this message from System

Attention!

Your solution 114875501 for the problem 1515B significantly coincides with solutions nmp/114873698, calabashgirl/114875308, bnkalya1502/114875501, sleeping_samurai/114904548. Such a coincidence is a clear rules violation. Note that unintentional leakage is also a violation. For example, do not use ideone.com with the default settings (public access to your code). If you have conclusive evidence that a coincidence has occurred due to the use of a common source published before the competition, write a comment to post about the round with all the details. More information can be found at http://mirror.codeforces.com/blog/entry/8790. Such violation of the rules may be the reason for blocking your account or other penalties. In case of repeated violations, your account may be blocked.

First of all , I do not even know who the above mentioned people are , neither did I used any online compiler . Although I agree that the above codes are similar but this is probably a coincidence because for an easy problem like this (given that there were 10K+ participants) , there are a limited types of implementations possible .

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

False Accusation of cheating in Codeforces Global Round 14. Got this message today. MikeMirzayanov

Attention!

Your solution 114904088 for the problem 1515B significantly coincides with solutions shart23/114880136, ThakurSaab/114904088. Such a coincidence is a clear rules violation. Note that unintentional leakage is also a violation. For example, do not use ideone.com with the default settings (public access to your code). If you have conclusive evidence that a coincidence has occurred due to the use of a common source published before the competition, write a comment to post about the round with all the details. More information can be found at http://mirror.codeforces.com/blog/entry/8790. Such violation of the rules may be the reason for blocking your account or other penalties. In case of repeated violations, your account may be blocked.

My Submission: 114904088 ......His Submission: 114880136 Problem B was quiet straight forward, and there are not much ways you can write the code for this problem if you try the same approach. In this case, me and tem_shett happened to use same approach for this problem. This is just a mere coincidence, and is quiet shocking for me becasue my solution has never been skipped or hacked before. Will this be rectified or I have to lose +43 for this contest ?. PS — I had a doubt, why am I the only one between the two of us who is penalized.

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

    Both of these codes are line by line the same except variable names.

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

      Yeah, I know. And that's mere coincidence. For such simple problems, the probablity of people writing similar codes is much higher.

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

When will t-shirt winners be announced?

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

    I have made a list,according to this code:

    T-shirt winners:

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

Congratulations to t-shirt winners!

List place Contest Rank Name
1 1515 1 Radewoosh
2 1515 2 ksun48
3 1515 3 Um_nik
4 1515 4 Benq
5 1515 5 yhx-12243
6 1515 6 tourist
7 1515 7 duality
8 1515 8 jiangly
9 1515 9 LJC00118
10 1515 10 NotaMotuaQAQ
11 1515 11 tatyam
12 1515 12 Golovanov399
13 1515 13 LayCurse
14 1515 14 Elegia
15 1515 15 Maksim1744
16 1515 16 _h_
17 1515 17 maroonrk
18 1515 18 244mhq
19 1515 19 ehnryx
20 1515 20 nocriz
21 1515 21 receed
22 1515 22 never_giveup
23 1515 23 nantf
24 1515 24 hitonanode
25 1515 25 heno239
26 1515 26 Ormlis
27 1515 27 natsugiri
28 1515 28 dlalswp25
29 1515 29 Isonan
30 1515 30 gisp_zjz
57 1515 57 orzdevinwang
90 1515 90 atomicenergy
95 1515 95 Egor.Lifar
102 1515 102 dorijanlendvaj
124 1515 124 Kaey
131 1515 131 FoodSheep
169 1515 169 Andycipation
186 1515 186 natofp
195 1515 195 YeongTree
223 1515 223 N.N_2004
228 1515 227 01191020csl
255 1515 255 yuto1115
260 1515 260 __23333
262 1515 262 aa2985759
311 1515 311 njupt_lyy
322 1515 322 lucasr
323 1515 323 momohara
337 1515 337 Lidox1145143344
362 1515 362 Emilan
479 1515 479 _su1sen