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

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

Hope that everyone enjoyed the round. Feel free to ask questions in the comments if you do not understand any part of the editorial

1672A - Log Chopping
Author: errorgorn

Hints
Tutorial
Solution

1672B - I love AAAB
Author: errorgorn

Hints
Tutorial
Solution

1672C - Unequal Array
Author: maomao90

Hints
Tutorial
Solution

1672D - Cyclic Rotation
Author: errorgorn

Hints
Tutorial 1
Tutorial 2
Solution 1
Solution 2

1672E - notepad.exe
Author: errorgorn, oolimry

Hints
Tutorial
Solution

1672F1 - Array Shuffling and 1672F2 - Checker for Array Shuffling
Author: errorgorn

Hints
Tutorial
Solution for F1
Solution for F2

1672G - Cross Xor
Author: maomao90, errorgorn

Hints
Tutorial
Solution

1672H - Zigu Zagu
Author: maomao90, errorgorn

Hints
Tutorial
Solution

1672I - PermutationForces
Author: errorgorn

Hints
Tutorial
Solution
Разбор задач Codeforces Global Round 20
  • Проголосовать: нравится
  • +135
  • Проголосовать: не нравится

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

Auto comment: topic has been updated by maomao90 (previous revision, new revision, compare).

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

Testdata for E was somewhat a little weak, I passed with parrel binary search with some optimizations. In the actual testdata it took no more than $$$500$$$ queries to find the answer.

Can anyone hack me?

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

    Try this:

    6
    1990 1997 1992 1994 1995 1989
    

    In fact, there is a $$$20\%$$$ probability that your solution will use more than $$$n+30$$$ queries, when $$$n=6$$$ and $$$l_i=2001-i-d_i$$$, where $$$d_i$$$ is randomly chosen in $$$[0,10]$$$.

    P.S. I didn't do enough experiments so that maybe the probability is not exact at all.

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

Me Mister Bebra!

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

My solution for D failed pretest 3. What I did is I went from right to left in array b maintaining a set current that contains all the indices in a that are being used, and a map extra that stores a count of all the extra values I can use.

Case1 b[i] = b[i — 1]: I will consider b[i] and b[i — 1] together. I find the greatest element in the set, let's call if g. I then iterate from g decreasing. In the current index k, if it isn't in current I skip it. Otherwise if it's equal to b[i], I'll remove k from current and break out of the loop. If it's not equal to b[i], I check if I have an extra a[k] in my map. If not, the answer is NO. Otherwise, I decrease the count by 1, remove k from current, and continue; At the end, I add b[i — 1] to the map extra so that I can use it in the future.

Case2 b[i] != b[i — 1]: I'll consider b[i] by itself. Then I'll do the exact same proccess as in Case1. The only difference is that I won't add b[i — 1] to extra and I'll just move on to the next i.

At the very end, array a might have some leftover elements. I will iterate over all these elements and see if I have enough values in extra to match them all. If I do, then the answer is YES. Otherwise, the answer is NO.

Is my logic wrong? 154756012

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

    Input:

    1
    5
    4 4 1 1 4
    1 1 4 4 4
    

    Expected Output: YES

    Your Output: NO

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

      I'm a little puzzled myself. I'm doing more or less the same thing, and I pass your given test case.

      154775344

      Edit — ah I see the issue, nvm

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

I've spent 1 hour 30 minutes looking for a bug in my solution of D (got WA on the 3rd test)... After the round finished I updated the page every minute, waiting for testcases to be shown... And what I see now is only "wrong answer expected YES, found NO [515th token]", because the test data is truncated.

I'm begging to look at the full testdata for test case 3, this is my only dream now

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

I think that problem H was really misplaced. Reading it afterward, it seems pretty straightforward, but I didn't try it during the contest because I thought it would have been much harder.

Also, making 1 1 a system test rather than a pretest for E really screwed a lot of people (including me) over.

Overall, it was a good contest!

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

In Problem B, I couldn't understand how AABBABAAAABABABAABAB can be acheived(Output is YES) as they are two succesive B's and good strings are AB, AAB, AAAB,..., so there must be atleast one A between two succesive B's and 'B' is bad string. I believe deletion of one character or substring is not allowed. Sorry if it is too dumb, but could anyone can explain this to me Thanks

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

    The problem says "Choose any position of s1 and insert some good string in that position."

    So we can insert AB into the middle of another AB which results in AABB

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

    We can do string AABB like this. 1) empty -> AB 2) AB -> AABB (A+AB+B) So we got the string like AABB

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

    Ohh I got it now

    Thank you so much

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

// Super Idol的笑容 // 都没你的甜 // 八月正午的阳光 // 都没你耀眼 // 热爱105°C的你 // 滴滴清纯的蒸馏水 Now this is epic

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

    Where is that from? I mean why is everyone posting this in the comments

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

      It's in the solutions above? If you mean what does it mean then it's an epic beautiful song

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

I found a different, possibly simpler, solution to H (Zigu Zagu). As in the hints I always remove a maximal segment. There are four possibilities:

  1. The endpoints of the segment are the same (e.g. we have ..1|101|1..). If we remove this segment we remove two pairs of consecutive 0s or 1s, but create one new pair of consecutive 0s or 1s

  2. Its endpoints are different (e.g. ..0|01|1..). In this case we remove one pair of consecutive 0s and one pair of consecutive 1s, without creating any new pairs of consecutive 0s or 1s

  3. One of its end points is at the end of the substring. Removing the segment simply removes one pair of consecutive 0s or 1s.

  4. The segment is the whole remaining substring. We always finish like this.

This means that every segment of type 1 or 3 reduces either the numbers of pairs of 0s or the number of pairs of 1s by 1. This reduces the number of remaining maximal segments by 1. Every segment of type 2 reduces both the number of pairs of 0s and the number of pairs of 1s by one, hence reducing the number of maximal segments by 2. As such our sequence should be:

  • Remove all possible segments of type 2. As long as there are pairs of both 0s and 1s there will always be at least one segment of type 2; so this will take min(0 pairs, 1 pairs) steps

  • Remove all remaining type 1 and type 3 segments. This will take a number of steps equal to the number of remaining 0 or 1 pairs, which will be max(0 pairs, 1 pairs) - min(0 pairs, 1 pairs)

  • Remove the last segment.

This gives a total of max(0 pairs, 1 pairs) + 1 steps.

To implement this, do a pass through the string calculating the number of 0 pairs and 1 pairs before each element, and we can then trivially calculate the number 0 pairs and 1 pairs for each query, and hence the answer to each query.

See https://codeforces.com/contest/1672/submission/154753079 (Python)

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

Anyone interested can check my code 154764444 for problem F1 (easier to understand than editorial).

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

About A's tutorial, seems $$$\sum_{k=1}^na_i$$$ there is a mistake

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

Finally I got FST on problem E because I set the upperbound of binary search 4e9 but not 5e9, and I got WA on test 20. Anyway, it's a good contest with excellent problems.

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

I don't know why I get TLE on problem D 154740846. I think it's O(N). Can someone help me.Orz

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

I could have reached cm today if i didn't fail in (E) Main tests, (〒﹏〒)

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

Misprint In editorial of D, tutorial 1, case 3: "we delete an occurance of ai in S and decrement j", We should decrement i instead of j.

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

Does anyone has a segtree solution for H? I was stuck on how to correctly merge two segments together... And I guess there must be some smart way of doing so.

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

In editorial of D, tutorial 2, I can't understand what is this saying : "As such, we can consider mapping elements of b into elements of a. More specifically, consider a mapping f where f is non-decreasing, bi=afi and we increment cfi by 1 for all i". Can anyone elaborate please?

Thanks in advance.

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

Nice contest, although I did not perform well.

Problem A is amazing. I use SG function to solve it, even though I felt that there must be a simpler solution during the contest. It turns out that my guess is right when I read tutorials and notice that I have missed the observation mentioned there.

It does not take me too much time to find a solution to Problem B, but I forget a corner case which leads to a WA.

It also needs some observation for problem C. I use almost the same idea as in tutorials. It is lucky that my first try is correct.

I get stuck in problem D from the beginning, and, until the end of contest. I find that somehow I am quite bad at such kind of problems. During the whole contest, I have never got any chance to get close to the idea in the tutorials.

I really get depressed when I see the top ones in the first page of standings, solving D within 15 minutes. This problem is an almost impossible task for me, while it is just like a warm up practice for them.

But now, what I can do is only to work much harder and practice more. There is no time for depression.

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

    Permutation problems are irritating.

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

    Instead of taking sadness from this round, take this: Whenever there is a question of applying operations some number of number. Try to think of applying operations in reverse.

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

Last line of tutorial of problem H: shouldn't it be "if $$$a_{l-1}\neq a_l$$$" ?

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

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).

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

OperationForces xd

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

Is H too similar to this problem? 1329D - Dreamoon Likes Strings

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

An only *3000 problem I?? I think the difficulty is too underestimated for such a huge-amount-of-code data structure problem.

By the way, ♪♪Super Idol的笑容 都没你的甜♪♪ XD. Is that song also got popularized in Singapore?

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

wrong answer expected NO, found YES [32nd token] problem D (Test: #2) can i find this test case somehow?

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

I think there is a typo in editorial for D. For the line

Otherwise, we delete an occurance of ai in S and decrement j. If we cannot find ai in S, it is impossible to transform b to a.

Instead of decrement j, it should be decrement i.

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

In editorial of F1: "Proof: (⇒) There exists a cycle decomposition of the graph that uses at least cnt1+1 cycles. Since a single element of 1 can only go to a single cycle, there exists a cycle without 1."

We are basically decomposing such that each cycle has only one occurrence of element 1. Why don't we need to do for elements 2, 3,...

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

    Because we only want to prove that there exist a cycle without $$$1$$$? So we do not have to care about what happens to any other element

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

F1 the Checker comment said "wrong answer B does not have the minimum possible sadness (test case 33)"

7
7 2 5 4 7 4 2

I Print 4 7 2 5 2 7 4

Why I Wrong answer?

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

Dislike for referring to politics in task E

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

I am still confused about the graph representation of problem F1/F2. Why can we build the graph by rep(x,1,n+1) al[arr[x]].pub(brr[x]); in the sample solution of F2.

As far as I understand, a permutation has a cycle representation, for example, the permutation 1 2 3 4 5 -> 1 3 5 2 4 can be represented by circles $$$(1)(2,4,5,3)$$$. But it seems that the construction in the solution is different from this kind. So far I couldn't understand where the idea comes from. Can anyone post some detailed tutorials or other related resources or problems?

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

Edit: Deleted.

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

in problem F1 ,why the lower limit of number of swaps of every cycle of length x equal to (x-1)?

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

    For example, if $$$x=5$$$, we can turn 1 2 3 4 5 into 2 3 4 5 1. And that costs at least 4 swaps.

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

      ok but why the number of swaps can't be less than x-1 in this example?

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

        You can think that there is an edge from $$$a_i$$$ to $$$b_i$$$. If we let $$$b_i=a_{i+1}$$$, it will form a cycle. In each swap we can only let at most $$$1$$$ number to it's right place, so we should have at least $$$x-1$$$ swaps to turn $$$a_i$$$ into $$$b_i$$$.

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

          can you please explain the construction part in F1?

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

            consider the following example : 1 2 3 1 2 it contains two cycles :(1 2 3) and (1 2),

            find all of these cycles and shift them left by 1 , so the cycles after shift will be (2 3 1),(2 1) respectively.

            then put these cycles in their original positions in the array, so the array will become :2 3 1 2 1

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

    The proof by SpadeA261 isn't too correct

    In each swap we can only let at most 1 number to it's right place

    Take the cycle of size 2, in 1 swap we can move both numbers into its right place.

    A correct proof is as follows.

    There are $$$2$$$ types of swaps (pretend the trivial swap that swaps an element with itself doesn't exist):

    • swaps that swap elements in the same cycle
    • swaps that swap elements in different cycles

    In the first type, the number of cycles will always increase by $$$1$$$. In the second type, the number of cycles will always decrease by $$$1$$$.

    Anyways we can see that the number of cycles can only increase by at most $$$1$$$. So When there is a single cycle of length $$$x$$$, we need at least $$$x-1$$$ moves to break it into $$$x$$$ cycles, with all length $$$1$$$.

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

Can someone tell why there should be X no of some cycles ? why cant be X no of chains ? i1->i2->i3->i4->i5 ? something like this. Isn't having cylce itselfreduce one swap so I was thinking in something in lines of X no of swap chains instead of cylces ?