Автор awoo, история, 5 лет назад, По-русски

Привет, Codeforces!

В 14.07.2019 17:45 (Московское время) состоится Educational Codeforces Round 68 (рейтинговый для Див. 2).

Продолжается серия образовательных раундов в рамках инициативы Harbour.Space University! Подробности о сотрудничестве Harbour.Space University и Codeforces можно прочитать в посте.

Этот раунд будет рейтинговым для участников с рейтингом менее 2100. Соревнование будет проводиться по немного расширенным правилам ICPC. Штраф за каждую неверную посылку до посылки, являющейся полным решением, равен 10 минутам. После окончания раунда будет период времени длительностью в 12 часов, в течение которого вы можете попробовать взломать абсолютно любое решение (в том числе свое). Причем исходный код будет предоставлен не только для чтения, но и для копирования.

Вам будет предложено 7 задач на 2 часа. Мы надеемся, что вам они покажутся интересными.

Задачи вместе со мной придумывали и готовили Роман Roms Глазов, Адилбек adedalic Далабаев, Владимир vovuh Петров, Иван BledDest Андросов и Максим Neon Мещеряков. Также большое спасибо Михаилу MikeMirzayanov Мирзаянову за системы Polygon и Codeforces.

Удачи в раунде! Успешных решений!

Поздравляем победителей:

Место Участник Задач решено Штраф
1 Benq 7 347
2 Geothermal 6 120
3 tmwilliamlin168 6 168
4 square1001 6 174
5 neal 6 174

Поздравляем лучших взломщиков:

Место Участник Число взломов
1 algmyr 8:-4
2 Half-Blood_Prince 3:-1
3 plusplus6408 2
4 El_Profesor_Aegon 2
5 user515 8:-13
Было сделано 47 успешных и 344 неудачных взломов.

И, наконец, поздравляем людей, отправивших первое полное решение по задаче:

Задача Участник Штраф
A dorijanlendvaj 0:01
B MesyuraTheOldDumbGoblin 0:04
C aneesh2312 0:04
D Benq 0:09
E Denisov 0:21
F Benq 0:15
G ecnerwala 1:07

UPD: Разбор опубликован

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

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

Typically for educational rounds (and for this one in particular), is the intention to have strong pretests to try to prevent failing systests, or to have weak pretests to encourage hacking?

Just trying to get a sense for how much I should trust the pretests tomorrow. :)

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

Hoping for good problems and strong pretests! cough subarray sorting cough

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

Please Less greedy :(

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

awoo is a boy or a girl?

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

The pretests of D last time were VERY weak.

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

India is not in World Cup Finals and you can totally participate without any hesitation

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

Please no Hackforces like last time (C and D).

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

I love contest!!!

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

Hopefully I can make blue this contest! I've been going after it ever since I reached my max rating, so hopefully this will be it.

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

Hope for no accident. Haha~

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

Hope that I'll become blue after this contest! :D

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

Wish I can become a candidate master.

What I need is only +26 rating. I think I can achieve that:D

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

I love educational constests!

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

I hope that everyone get the rank which they want. I want get closer to be a blue.

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

agc035 was just moved by 30 minutes, and due to this will propably overlap with this one.

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

There's an Atcoder round today that was delayed to conflict with the first 5 minutes of this round. Would it be possible to postpone this round by 10 minutes?

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

    On the other hand, it is also possible to hurry up on Atcoder, and finish some minutes before the constest ends :)

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

Hopefully I can become purple in this round.

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

Due to the delay in the contest on AtCoder, we moved our round for 10 minutes.

===

По причине переноса контеста на AtСoder, мы подвинули наш раунд на 10 минут.

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

    why not delaying it for 30 mins like Atcoder? Many people would have more time to have a rest after agc.

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

      But someone who must stay up late for this contest may not think so :<( (such as Chinese)

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

I used to be a cyan coder once. But I've seen a downfall. Wish me luck CFians!!

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

I love educational rounds (^.^)

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

Good Luck && Have Fun !

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

QueryForces is back!

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

(F)educ/k one love

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

GO Federer !!

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

Are Div.1 Participants counted in calculating rating changes of Div.2 participants?

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

How to solve D??

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

    You can make an array "win[i]" which means that: win[i]=1: if n=i, Alice wins win[i]=0: if n=i, Bob wins

    Make a program that generates the values of the array, and then find the pattern. You will easily find it.

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

      You wont find it easily as I did not even after searching for it more than half the contest, submitting aprox ten times.

      How is a strategy to solve such one?

      I did write, paint... several pages on paper, but was not able to get the pattern right.

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

        I just found all the patterns when k=3, 4, 5, 6, ...

        When k%3==0, the pattern was a little different than when k%3!=0.

        So I divided the cases into two, that is:

        1) k%3==0

        2) k%3!=0

        Then you will be able to find the pattern. If you can't on case 1, write (k+1) numbers on one row like

        able[0] able[1] ... able[k]

        able[k+1] able[k+2] ... able[2k+1]

        ...

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

          I did. For k=3, 4, 5, 6 I drew the array for index up to 15-20 by hand...

          In fact, just now after inspecting several working solutions, I think I would not be able to write it down as code correctly.

          Seems that is not my kind of buisness.

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

How to optimize N^2 solution for F?

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

    Denote $$$f(l,r)=\sum\limits_{i=0}^{l}\binom{r}{i}$$$, Try to move from $$$(l,r)$$$ to $$$(l,r+1)$$$ and three other intervals in $$$O(1)$$$. Then apply Mo's algorithm to solve the problem in $$$O(n\sqrt{n})$$$.

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

      Wait? Don't we have to calculate $$$f(l,r)=\sum\limits_{i=0}^l(\frac{1}{2})^i\binom{r}{i}$$$? Or my expression is wrong(or needs more optimization)?

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

        We compute the overall answer as the sum of the probabilities that we solve each puzzle. We solve puzzle $$$i$$$ with probability

        $$$\frac{f(l, i)}{2^i}$$$

        for an appropriate value of $$$l$$$.

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

        No. It should be $$$\sum\limits_{i=0}^{l}(\frac{1}{2})^{r}\binom{r}{i}$$$.

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

          Oh thank you. I found my mistake.

          (If I didn't make this mistake I would solve it...)

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

      how do you do that?

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

    There's a solution that runs in $$$O(N \log MOD)$$$, where the second factor comes from computing modular inverses in the process of building the choose function. I can't explain it particularly well, but the gist is that we define the same sum as Roundgod did and note that the required $$$l$$$ will generally decrease over time. Then, we can transition from $$$r$$$ to $$$r+1$$$ quickly (think about Pascal's triangle to see how this works) and can simply add combinations necessary to change $$$l$$$ in order to get the final answer for a certain $$$(l, r)$$$.

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

      We can even solve it in $$$O(n)$$$ — linear time. That's because we can calculate $$$I_x = $$$ modular inverse of $$$x$$$ mod $$$p$$$ by inductively calculating by $$$I_x = I_{p \ mod \ x} \cdot \left (- \left \lfloor \frac{p}{x} \right \rfloor \right )$$$, and so we can calculate $$$J_x = $$$ modular inverse of $$$x!$$$ mod $$$p$$$ with $$$J_x = J_{x - 1} \cdot I_x$$$. That's the all inverses we need to calculate all $$$C(n, k)$$$ and finally the answer.

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

    Let $$$s_i = T - \sum_{j \leq i} t_j$$$. If $$$\ell$$$ is the last crossword completed, at most $$$s_\ell$$$ of the crosswords up to $$$\ell$$$ can take an extra second, and at least $$$s_{\ell+1} + 1$$$ of the crosswords up to $$$\ell + 1$$$ must take an extra second.

    The number of possibilities to check for any fixed $$$i$$$ is linear (the extra seconds up to $$$\ell$$$ and the extra seconds up to $$$\ell + 1$$$ differ by 0 or 1). Also, since $$$s_i$$$ is decreasing, the number of possibilities for all $$$i$$$ put together is still linear.

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

I don't like game theory because I ALWAYS lose when playing game with others.

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

RIP for those who thought that the player can move up to K cells in each turn
Not 1, 2 or exactly K.

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

    Well. I would have read question twice. If I read this.
    Because this problem is standard nim game and expecting it as D would have been surprise for me.

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

      How is "up to $$$K$$$" standard Nim? I think "up to $$$K$$$" can be done by simply checking value modulo $$$K + 1$$$?

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

        A bad selection of words.
        What I meant was that this is rather known. And would have got faster submissions that B/C.
        I read about it (simply checking value of modulo K+1). When I read some introductory level game theory blogs. Thats the reason I used "standard Nim".

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

I'm sure I saw problem B the same but don't remember in which round !

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

Solution for problem D:

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

Good contest, thanks)

How to solve E?

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

    Use lazy propagation and segment tree. That's the hint.

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

      can be solved just with a fenwick tree with line sweeping technique

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

        Even just with ordered_set 57040076.

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

          Can you please explain your approach?

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

            Fix a vertical line as the left side, add horizontal lines that start before it and finish after it. Now, sweep to right to see other vertical lines (as the right side of rectangle). Just keep track of horizontal lines (erase a horizontal line when you reached the endpoint of that). My code is easy to understand.

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

          your code gives wrong answer for 5 0 0 0 10 10 0 10 10 -1 3 20 3 1 3 5 3 0 2 30 2 /* ans=1; your code ans=0; */

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

            no pair of horizontal segments shares any common points, and no pair of vertical segments shares any common points.

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

      I had been thinking on using segment tree for about hour when found O(n^3) algorithm with bitset. I still do not know/understand how to solve it using segment/fenwick tree. Looks like i blundering something about it...

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

    Make bipartite graph with vertices on the left corresponding to horizontal segments, and vertices to the right — to vertical ones. If two segments intersects, there is edge between corresponding vertices. Now lets iterate over all pairs of vertices on the left. Lets there are K common vertices on the right, then we need to add K * (K — 1) / 2 to the answer. Complexity is $$$O(N^3)$$$, but it is easy to see, that we can optimize this with bitsets, and overall complexity would be something like (N / 2) * (N / 4) * (N / 32), which seems to be fast enough (it is around 0.5 billion simple operarions)

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

      You can find a number of common vertices K by taking a square of an adjacency matrix. And taking square of a matrix can be done in O(n^2.8)

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

      Could you explain what do you mean by this "__Lets there are K common vertices on the right_," Thanks in advance.

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

        Let's fix two vertices on the left side (A and B). Let's call vertex C on the right side common if C is connected to both A and B.

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

      My bitset solution gave TLE-5 but using pragmas it passes in 1965ms. To optimize it should we make bitset matrix based on smaller count of horizontal or vertical segments?

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

      Could you explain how you got the complexity as N/2*N/4*N/32. Thanks in advance.

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

        Without loss of generality, assume that there are more vertical segments, than horizontal one. Now number of horizontal segments is no more than N / 2. Let's iterate over all unordered pairs of horizontal segments (there is no more than (N / 2) * (N / 4) such pairs) and AND their bitsets, which is N / 32.

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

I'm pretty sure I had the right idea for D by printing Alice or Bob for values of n and k mod 3, along with a special case for k = 3. However, I got WA on case 3; could anyone tell me what I was missing?

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

Отличный раунд. Спасибо авторам!

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

can someone tell me what could be the pretest 2 in the B question,Idk why my code was not getting accepted though I tested all possibilities :(

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

can someone tell me what could be pretest 2 in question B, i tried every damn possibility, my code worked but it wasnt getting accepted.

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

I hope that this round won't be a HACKducational round.

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

LOL, First time A,B and C solved. problem C was quite easy i guess.

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

Some one please give a proper explanation how to solve D?

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

    The best way to solve D has already be given. Generate a few cases and observe the pattern. You can generate cases like this: A position i is marked 'W' if there is a winning strategy if it starts at i, otherwise it is marked 'L'. You can calculate all 'marks' as: if all positions that you can reach from here are marked 'W', then that means no matter what move you do, your opponent has a winning strategy so mark the current position 'L'. Otherwise, mark it 'W'.

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

Its sad that, i misunderstood Problem D. I thought Alice and Bob can only move i->i-k, if i>=k, and can take a step i->i-1 or i->i-2, only when i=1 and 2 respectively.

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

In my profile it says i have registered 50 years ago ( which is not really possible ).

Can anyone help me with fixing this .

EDIT: it is fixed now

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

https://codeforces.com/contest/1194/submission/57052535 can someone tell me why isn't it working ? I am 2*x , but random no. are being printed In the same way, https://codeforces.com/contest/1194/submission/57055104 if u copy code of this question and run on DevC++ , the answer is coming right , but on codeforces its coming wrong

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

Can someone please help me in problem B . What i was doing is to find min_row first and find its respective min_col both having minimum number of white paint . Also again finding min_col first and find it's respective min_row with least white tiles. Answer would be minimum of both 2 possibility . But i m still getting wrong . Any counter case ? My submission

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

    The thing is, you need to consider all rows that have least tiles, because your program chooses the first one and that might not be optimal since there could be another row that could have the same amount of white paint, but that other row might intersect with another column,with minimum white tiles, on a white cell which means that by painting that white cell on which they intersect, you reduce the amount of white paint on both the column and the row with the least amount of white paint. Hope I helped.

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

This is tastcase 2 on Problem B. Is it Strange?

15 158 169 ..**....**...*..*..****.....**.**.**..*****....*..*...*...*.*...*.**....*..*.*****.******...******.*..*...*..*...**.***..*..*.*.***.*..*.**.***.*..*.........*..**...**.. ..**...*.*.*.****.*..***...**.**.*..*****.******....*.*.........***.****.*..**....***.*.*.****..*****.*.....**..*...*****.***.*..***.*****.*.*****.***.*...**...*..**** ...*..*..***.**...**....**...***.*****.*..*.*.**..*.**..****...***.....**.**.*...****.*......*..*..***..****.**....***..*...***...***...*..********.*.**...

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

    That's only a part of it. The rest is snipped off and replaced with ... at the end which happens to look like part of the grid.

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

What happens if our hack is incorrect? I am new to hacking. Are there any points for successful hack?

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

Why official standing showing unofficial participants !?

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

go for next contest to better rating

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

Don't know why but I can't find this contest on contests tab even dough I participated. Does anyone else have this bug?

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

    It doesn't appear there until the ratings have been updated.

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

D problem is a good type of game theory

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

    I didnt solve it so maybe I am not objective, but its nothing special. Still, of course its better than theoretical game theory problems which involve grundy numbers or something. I dont think anyone loves that.

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

how to solve E?

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

_Aragorn_ Hacked himself purposely (Problem A). Isn't it illegal? Link: https://codeforces.com/contest/1194/submission/57060726

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

How to generate solution for D without observation? Any simple technique and proof?

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

    Fix $$$k$$$, and for each $$$m<=n$$$, $$$f(m)=A$$$ if Alice will win if the strip were to begin at $$$m$$$, and $$$B$$$ otherwise. Obviously $$$f(0)=B$$$ and for the rest, $$$f(m)=A$$$ if and only if exactly one of $$$f(m-1), f(m-2), f(m-k)$$$ is equal to $$$B$$$. (For the rest of the proof we will not deal with the size of $$$m$$$ with respect to 1, 2, $$$k$$$, the proof will still be the same with all those constraints added, just a bit messy).

    We shall proceed by inducing on $$$m$$$ in each case of whether $$$3\mid k$$$ or otherwise. In either case, we observe that $$$f(m)=B$$$ means $$$f(m+1)=f(m+2)=A$$$ (reason being explained above). We claim that for the first case, $$$f(m)=B$$$ iff $$$3\mid m$$$, with base case $$$m=0$$$ explained. Now for inductive step, if $$$3\nmid m$$$ then either $$$3\mid m-1$$$ or $$$3\mid m-2$$$ and therefore $$$f(m-1)=B$$$ or $$$f(m-2)=B$$$, which follows $$$f(m)=A$$$. Otherwise $$$3\mid m$$$ and we notice that neither of $$$m-1, m-2, m-k$$$ are divisible by 3, and therefore by induction hypothesis $$$f(m-1), f(m-2), f(m-k)$$$ are all $$$A$$$, so $$$f(m)$$$ must be $$$B$$$.

    Now $$$3\mid k$$$ is tricky: the first $$$k-1$$$ values follow from the previous case, but $$$f(k)=A$$$. We, instead, consider modulo $$$k+1$$$ and the first $$$k+1$$$ values (0, 1, ..., $$$k$$$) should be clear. Now let $$$m\ge k + 1$$$, which means we should consider $$$f(m-1), f(m-2), f(m-k)$$$. For clarity, consider $$$m_0$$$ as the remainder of $$$m$$$ when divided by $$$k$$$. The induction claim, as suggested by others, is that $$$f(m)=B$$$ if and only if $$$m_0=0, 3, \cdots , k - 3$$$. We have the following cases:

    $$$m_0=0$$$, and $$$m-1, m-2, m-k$$$ are congruent to $$$k, k-1, 1$$$ modulo $$$k+1$$$, and by induction hypothesis it follows that all $$$f(m-1), f(m-2), f(m-k)$$$ are all $$$A$$$ so $$$f(m)=B$$$.

    $$$m_0=1, 2, k$$$: obvious from the previous case.

    The rest of the cases: since $$$3\le m_0 < k$$$, $$$m-1, m-2, m-k$$$ are congruent to $$$m_0-1, m_0-2, m_0+1$$$ modulo $$$k+1$$$. If $$$3\nmid m_0$$$ then either $$$m_0-1$$$ or $$$m_0-2$$$ is divisible by 3 and less than $$$k$$$, so either $$$f(m_0-1), f(m_0-2)$$$ is $$$B$$$ and this case is done. Otherwise, $$$f(m_0-1)$$$ and $$$f(m_0-2)$$$ are both $$$A$$$ so we only consider the last one, $$$f(m_0+1)$$$, which is also equal to $$$A$$$ since $$$3\nmid m_0+1$$$. This concludes the proof.

    Sorry for the poor organization, I am writing in a hurry (though it's fun to do so :P )

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

Good job to Dontdoprepaitisatrap for some high quality hacks: https://codeforces.com/submissions/laklouch

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

I changed just two characters in my first submission(douring contest) and I got AC for problem F after the contest (57059435). I was really unlucky during the contest. :(

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

Why put such a high bound on E when solution is n^2 log n? When n=5000 that is about 3*10^8 operations.My segment tree solution got TLE which cost me a lot of time before i finally stopped thinking about an n^2 solution and optimized my segment tree by a little bit to save those 200-300ms that i needed.

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

    You can solve it in O(K*(K-1)/2) bitset operations, where K = min(horizontal, vertical) so in the worst case, K = N/2. Considering each AND operation runs in N/64 more or less, it's a good complexity ~ 250.000.000 operations which run in aprox 1600 ms

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

      I thought of that during the contest but i thought that would get TLE much easier than the log n solution since it's essentially O(N^3). Interesting to know that works too.

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

Is there a rigorous mathematical proof to problem D (when k% 3 == 0)

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

    Think only about i-1 and i-2. A means Alice wins and B means Bob wins. This is the winning pattern, starting from n==0: BAABAABAABAABAA. Basically, if pos%3==0 the ans is Bob. This happens because you only reach positions that Alice wins form this pos%3==0 positions. When k%3==0, the lowest position that change is pos==k, and it is easy to see the reason why ( you cant go to pos-k because it is < 0). Then, a part of the winning pattern will become: AAApos, id of pos == k+1. So both pos-1 and ipos-2 will reach A, so the ans should be B. And we know that pos-k changed from B to A. So the unique ans to pos is B now. This is the same as restarting the winning pattern, so, this winning pattern in the range [0, k] will be the same as [k+1, 2*k] and so on. I know that this solution is not rigorous mathematical, but I hope it will help you!

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

      Thanks

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

      Assume k % 3 == 0. Let's iterate array from start. 0 is lose, 1 is win. So basically without the k jumps its all 011011011 or (011) repeating infinitely — start is losing, and you can get to start with 1 or 2 jumps so next ones are win, and third is always lose cause opponent wins. Now for first k cell we can't do k-jump so its all (011) then we suddenly can, and we jump to 0, so k'th cell gives us a 1 and the sequence ends like ...011011(1) last 1 being k+1'th position, or k'th index.

      Next, consider this lemma : k — jump is useful iff it lands us from 0 to 0 without k — jump. In this case, we get a 1 in that position where we are jumping from and jump to losing position. So what does that give us?

      At k+1'th index we have 0 again, because we end with three 1 and cannot do usual jumps and k-jump lands us on 1 too. K-jumps are useful only on every third position only, because we had a sequence (011). But every third position is 1 anyways, so we can discard k-jumps and we have repeating sequence of (011) starting from k+1'th index. This holds true until we get to 2*k+1'th index. Because of 111 shift, we have suddenly 0 at index 2*k+1 — k = k + 1 (try doing with k = 3 and 6 to see pattern easily) and we get again 1 at index 2*k + 1 and again there are three 1 there. You can use this reasoning to conclude that structure ((011) + 1) at the end is repeating, first (011) being taken k/3 times. Then knowing that, take remainder of n modulo k + 1 (counting last 1) and check. If we land on last index, return 1. Else divide remaining pattern modulo 3 and return 1 if remainder is 1 or 2.

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

How to solve B ?

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

    Imagine you are in Cell(x, y), now you have to make sure all cells in this row and column must be black. This means some white cells need to be painted. Now how many white cells are to painted? For this, just store the count of white cells in each row and column. Now if at (x, y), cells to be painted, X (lets say) =(White Cells in Row 'x' + white cells in Column 'y'); just make sure if current cell is white, you subtract 1 from X because it will be counted in both row as well as column. Just find minimum of 'X' from all cells in O(n*m); Hope it helps.

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

I was thinking to model Problem D in terms of recursion in n and k and then try to find out value using matrix exponentiation. Did anyone else tried it this way?

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

Pretests too strong only 30 successful hacks so far

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

Is there a better soultion for B than O(n*m).

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

    what do you mean ? don't you want to input the grid that's o(nm)

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

Hey, Guys I just did question A checkout its solution: link

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

I will be saved from NEWBIE!! [user:_seyed37_][user:Jefri_007]

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

The problem D Hao to deal with k%3=0 this case,I can't understand the ac code,HELP ME !!!!

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

i don't think that there will be much system failures . Pretest almost cover the test cases set.

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

sir when editorial is going to be released?? need it .

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

How to solve E

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

    Make an events array of three types of events: vertical segment, horizontal segment left point, horizontal segment right point plus one. Sweep from left to right. At every coordinate first process all horizontal segment updates in a segment tree (update the y-value with plus or minus one). If you reach a vertical segment, consider it as the left side segment. Then for each fixed segment loop over all events to the right of it and update the segment tree accordingly. If you encounter another vertical segment, then add (number of horizontal segments intersecting both segments) choose 2 to the answer.

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

      When I was reading your answer I wondered what exactly "update the segment tree accordingly" means. If I understand correctly then you do the following: Once you fixed a vertical segment as left side of a rectangle you loop over all segments to the right of it: On every horizontal-segment-end you update the segment tree (i.e. decrease the corresponding y value by 1). On every horizontal-segment-start you do nothing. On every vertical segment you add some number of new rectangles to the result (as you described it). The reason that no operation is done on horizontal-segment-start is that the horizontal segments that start after our fixed vertical segment do not intersect with our fixed vertical segment and thus should not be considered. Did I understand this correctly or am I missing something?

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

        You're right. But this is kind of the same mistake I made (I had 16 wrong submissions): "On every horizontal-segment-end you update the segment tree (i.e. decrease the corresponding y value by 1)"

        The thing is, you have to store the start point of the horizontal-segment-end, because if you decrease by one and the segment has started after your left segment, then you'll end up undercounting the number of segments.

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

May you tell me where the Editorial is :>

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

When system testing will start??

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

System testing start

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

qwq

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

Quickest system testing seen on codeforces :D

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

Does cf has a YouTube channel. I guess if there is one on which veduo solutions to the contests can be provided , it will be of great help to beginners atleast .

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

editorial please??

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

LOL, I've pushed N^3/64 in E, really want to know the right solution. At first I've used bitset, which gave TL 4. After rewriting bitset myself, it gave AC in less than 600ms, that's amazing.

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

Who wrote solution for E with fenwick tree and complexity O(n^2logn)?

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

Can anyone please tell when will the editorial be out ??

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

Problem D

How to find pattern using generated ans sequence for several n,k??

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

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

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

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

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

Why is my solution for problem E giving TLE. I used line sweep algorithm with ordered_set. Time complexity: n^2 log(n)

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

    I think in one of the first blog posts introducing ordered_set to codeforces, they concluded that it was twice as slow as recursive segtree. My recursive segtree solution takes 1400ms on the problem, so it kind of makes sense that it could TLE.