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

Автор tourist, история, 7 лет назад, По-английски

AtCoder Grand Contest 019 will be held on Saturday (time). The writer is tourist.

Contest Link

Contest Announcement

The point values will be 300 — 500 — 900 — 1000 — 1700 (1200) — 2000 (1500). Note that the contest duration is unusual (150 minutes).

Let's discuss problems after the contest.

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

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

It is very pleasing as well as fearing to see you as a contest writer tourist.

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

Yesterday I had to cancel my weekend plans and got upset by that. Now I'm not that upset anymore.

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

tourist round? Oh Yeah!

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

Special mention when tourist is the problem setter:

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

I hope to get well in this contest, this wink has to mean something..

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

Looks like the whole world is waiting for this contest -> I hope that servers will handle such a huge number of participants.

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

Did anyone else get WA in last 4 tests in C?

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

Any hints for C?

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

how to solve B ? :)

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

    Consider all contiguous regions. of them. Now a [l... r] is superfluous if a[l] = a[r] as [l + 1... r - 1] is already checked. Subtract these from that.

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

    Good day to you,

    well a good hint is, that as long as "borders" of reversed substring are equal, then the string after reverse will be same as if it was reversed without borders.

    Also note that if this wouldn't happen, then |s|*(|s|+1)/2 (+1) possible solutions could apprear.

    Hope it helped a little bit.

    Good Luck & Have Nice Day ^_^

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

Solution for B is so simple but too difficult to come up with. ;(
How did you come up with it?

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

    It's obvious that if substring is palindrome reversing it won't change anything. And I noticed if s[l] = s[r], then reversing it will be same as reversing [l + 1, r — 1], so you need to substract such pairs.

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

    The hard way:

    • "prove" that any palindrome is bad and any non-palindrome is good (and unique)
    • code a solution using Manacher's algorithm
    • fail last sample (answer: 54)
    • print all strings my solution generates
    • find out why some are the same
    • look for a way to find pairs of same letters in same distance from given pivot (yay for overcomplicating)
    • give up, switch problem
    • return to it, start from scratch but with a correct condition this time
    • finally solve it.
    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится +23 Проголосовать: не нравится

      My first three steps were the same as yours :)

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

      Then atleast someone suffered like me. My steps:

      1. Look at points : 500 => Easy.

      2. Look at problem : WTF, how to solve?

      3. Think for some time, figure out swapping palindromes is invalid.

      4. Look at "abracadabra" : HTF is answer 44? How can 11 be bad?

      5. Look at standings : People solving trivially in 8 — 10 minutes.

      6. Start discarding Manacher. What is trivial and seems correct?

      7. No idea, write brute force Python code, print all invalids.

      8. Endpoints equal means invalid, scold yourself for being dumb.

      9. Believe in God, and that your observation is the sufficient condition.

      10. Code.

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

        and these are my steps :D :

        1.read problem !

        2.WTF :D

        3.after about 10 min think , I guess that it need some algorithm that I don't know !

        4.close contest page and go to my bed and sleep :))))

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

      My way:

      • guess that any palindrome is bad and any non-palindrome is good (and unique)
      • code a solution using Manacher's algorithm
      • fail last sample (answer: 54)
      • print all strings my solution generates
      • find out why some are the same
      • look for a way to find pairs of same letters in same distance from given pivot (yay for overcomplicating)
      • give up, switch problem
      • return to it, start from scratch but no clue
      • finally time is up
    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится +78 Проголосовать: не нравится

      Oh, that 54 is familiar :D I was afraid I'm the only one here, facing side effects of droptable coaching me for ICPC :)

      I really loved this problem — it made me feel stupid, then I had to guess solution from standings (there are not so many simple things you can do with string in 2 minutes), and then after figuring out why is it correct (only after the contest) I was amazed how simple&obvious it is.

      It is also funny how it uses some simple but not worn-out idea, but everybody goes into palindromes because they have been hyped a bit over last years :)

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

    I also stuck with this problem , ended up by doing it bruteforce(print out all of the same strings with different left and right) and finally got it xD

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

I have an easy solution to E in O(n2) with a sufficiently small constant, without using NTT, unlike 998244353 suggested. (p.s. I didn't bothered to check other solutions. It appears that first solvers have the same solution.)

int solve(int x, int y) {
    dp[0] = 1;
    for (int i = 1; i <= x; i++)
        for (int j = 1; j <= y; j++)
            dp[j] = (dp[j] + (long) i * dp[j - 1]) % mod;
    int ans = 0;
    for (int i = 0; i <= y; i++)
        ans = (ans + (long) dp[i] * inv[x + i]) % mod;
    return (long) ans * fac[x] % mod * fac[x] % mod * fac[y] % mod * fac[x + y] % mod;
}

We first observe that any valid swap is either:

  1. Swapping a (0, 1) with a (1, 0) (swapping ai, aj s.t. (ai, bi) = (0, 1), (aj, bj) = (1, 0))
  2. Swapping a (0, 1) with a (1, 1)
  3. Swapping a (1, 1) with a (1, 1)

Let x be the number of (0, 1) and y be the number of (1, 1). Clearly the number of type 1 swaps is x, and the number of type 2 or 3 swaps is y. As type 3 swaps do not interfere with other types, we assume there are y - i of them, multiply the answer by , and forget their existence.

Now we're left with x of (0, 1), i of (1, 1), and only type 1 or 2 swaps. Let g(x, i) be the number of possible swap sequences. Clearly,

Let g(x, i) = (x!)2(i!)f(x, i). Then clearly,

And for the final answer, we must sum over 0 ≤ i ≤ y, i.e.

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

    I think that tourist knew about this solution and made constraints lower for this to pass. If the only intended complexity was then why n is not up to 105?

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

      Better ask tourist directly for the reason.

      Anyway, I'd still post the comment as long as most of the world didn't know about this solution.

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

        Thank you for describing your solution! It's quite different from the editorial, so it's definitely worth explaining.

        Indeed, we had only intended, but shortly before the round discovered that it's nearly impossible to separate it from O(n2). Thus, we decreased the constraints to make it obvious that O(n2) works.

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

          It took a lot of work, but I was able to squeeze in a solution of F in .

          Let's first consider the case where N = M, and compute A[x] — the sum of the results over all possible Yes/No sequences. Clearly, A[0] = 0.

          We model the Yes/No sequence as lattice path from (N, N) to (0, 0). What happens at point (x, x) for x > 0? There will surely be a point where the path crosses the main diagonal again for the first time, that is, we reach state (y, y) for some 0 ≤ y < x.

          How many ways to do this are there, and how good they score? Let's assume that the we guess incorrectly at (x, x) and we move to a state (x - 1, x). Then, our path continues to (y, y + 1) and then continues to (y, y). It is the first time we reach the main diagonal, thus the path never crosses the "+1" diagonal. There are such paths. Since it is optimal to always guess the answer which has the most occurrences left, it is easy to see that this path scores exactly y points, plus whatever we expect to get from the path between (y, y) and (0, 0).

          Similarly, if we guess correctly at (x, x), we have the same amount of paths to (y, y), but we score one more point (the one at (x, x)).

          This combined yields the following recurrence:

          The second summand in the large sum times the right term can be computed first by a simple convolution. The term with A[y] can be then computed using linear convolution (of form ) in time.

          This yields 1500 points and fits quite comfortably into TL. To extend this to a full point solution, we need an extra linear step: for every point (x, x) we calculate how many paths there are for which this is the first point on the main diagonal from the path from (N, M) (again by using the above formula for lattice paths above the diagonal) and for each of them add M - x points to A[x].

          The TL is very tight in this case, so one needs to have solid NTT implementation, and when doing the linear convolution using Divide & Conquer algorithm (described here), one needs to cut-off the recursion at around 26.

          My quite convoluted (pun intended) solution: link

          EDIT: The editorial seems not to be present anymore, so I wasn't able to verify how much my solution matches it :)

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

      Maybe his mind is weak

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

could someone explain the "simple binary coefficient" for me :D

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

As expected, problems were very interesting. Words cannot explain the pleasure of a post-AC orgasm from this contest's problems.