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

Автор ko_osaga, история, 3 года назад, По-английски
  • Проголосовать: нравится
  • +188
  • Проголосовать: не нравится

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

How to solve G, M?

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

    G: The player with HP $$$X$$$ dies if and only if there exists a subsegment with sum at most $$$-X$$$. The case with ultimate is similar since the HP doesn't change.

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

How to solve Beautiful Numbers from Div2, Or Machine, Periodic Ruler ?

Or Machine looks like a grap. In Beautiful Numbers I tried greedy in multiset by finding the closest groups such 91, 82,73 and etc.. ,but it doesn't work.

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

    Periodic Ruler: Let's first find which $$$d$$$ satisfy that there exists a $$$s$$$ such that $$$\forall t, s[t]=s[t+d]$$$. We take any two $$$i,j$$$ such that $$$a_i \ne a_j$$$, it is obvious that all divisors of $$$|x_i-x_j|$$$ cannot be the period. Let's take the distances of all the two different characters and their divisors, which are all the numbers that do not satisfy the condition. Then, we have to remove the values that are impossible as minimum periods. Note that if $$$d$$$ is a period of $$$S$$$, then $$$S$$$ must satisfy $$$S_i = S_j$$$ for all $$$i \equiv j \pmod d$$$. If for some $$$0\leq i<d$$$, there does not exist a $$$j$$$ such that $$$p_j \equiv i \pmod d$$$, then we can put a character that has not been used yet. This ensures that it will not have a smaller period. Otherwise, the entire string is uniquely determined, and we only need to check if it contains a smaller period by brute force(Note that $$$d \leq 50$$$ in this case).

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

Thank you for the participation!

Problems were prepared by

Editorials and Gym contest are not prepared as of now. I will work on it.

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

    Could you please public the jury's solutions? Maybe it's helpful if there's no tutorial available yet. Thanks!

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

How to solve A?

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

    You realize that $$$E_{ij}$$$ can be decomposed as $$$P_i+Q_j$$$, and then reduce the problem to having row and column sums and trying to find a construction that gives these sums

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

      How to find the sum of the first/last row/column?

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

        Denote by $$$P_i$$$ the sum of the $$$i$$$-th row and $$$Q_i$$$ the sum of the $$$i$$$-th column. Since we know $$$P_{2}, ..., P_{n-1}$$$ and $$$P_1 - P_2 - P_3 - ... - P_n$$$, we can get $$$P_1 - P_n$$$. Similarly we get $$$Q_1 - Q_n$$$.

        Now since $$$\sum_{i=1}^n P_i = \sum_{i=1}^n Q_i$$$, we can also get $$$(P_1+P_n) - (Q_1+Q_n)$$$. Thus, we can know $$$P_1, P_n, Q_1, Q_n$$$ up to an unknown additive constant.

        Finally using an element in $$$E$$$ (say $$$E_{11}$$$) to calculate the unknown additive constant.

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

Was it the intention to prevent $$$O(n \log n)$$$ from passing in B? Time limit is rather ambiguous, our solution barely fits locally but fails at test 10 in the system.

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

Any hints for L and F? :)

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

    L: Compute MCMF in $$$O(VE \log V)$$$ by Dijkstra with potentials. The symmetric difference of matching from $$$G - {e}$$$ and $$$G$$$ constitutes a path from $$$s \rightarrow t$$$. If you add an edge from sink to source, you can compute the path with Dijkstra, using the same potentials.

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

      Well, you may need one more path, so you need two runs of Dijkstra algorithm. And I failed to squeeze time limit.

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

        Sorry, the TL is tight to break SPFA approach. And I don't understand why we need one more path.

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

          Consider test

          2 2 3
          1 1 2
          1 2 10
          2 2 2
          

          Best set is using only edge #2. But if you remove it, you can add both #1 and #3. But first path search can do only one of them.

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

    F: Random approach does not help. You would need to start with a deterministic solution which uses $$$2\sqrt{V}+\alpha \approx 2000+30$$$ queries where $$$V=1\,000\,000$$$:

    • $$$t = Query(1, 1\,000\,000)$$$ gives a vertex which must be included in the cycle.
    • Now $$$a_i = Query(t, i)$$$ for i=1 to 999, $$$b_i = Query(t, i*1000)$$$ for i=1 to 1000. Any positive integer $$$n \le 1\,000\,000$$$ can be represented as $$$x*1000-y$$$, where $$$1 \le x \le 1000, 0 \le y \le 999$$$, so some results of the query(namely $$$b_x$$$ and $$$a_y$$$) will be the same. $$$Query(t, c) = Query(t, d)$$$ gives you the information that $$$c-d$$$ is multiple of the cycle length $$$n$$$.
    • Factorize $$$D=c-d$$$, and for each prime factor $$$p$$$, query $$$Query(t, D/p)$$$. If this equals to $$$t$$$, divide $$$D$$$ by $$$p$$$ and continue the process. Else, the answer $$$n$$$ should be multiple of $$$p^e$$$($$$e=ord_p(D)$$$), and go on to the next prime factor.

    For $$$Q \le 900$$$, you should apply various tricks to optimize the second process. All you need is: for all $$$n \le 1\,000\,000$$$, one of $$$q_i - q_j$$$ is a multiple of $$$n$$$. Note that you can query some large integers like $$$2\cdot 10^{18}$$$; this helps a lot. Intended solution uses $$$\sqrt{2V/3}+\alpha$$$ queries.

    Some hints about various tricks
»
3 года назад, # |
  Проголосовать: нравится +26 Проголосовать: не нравится

How to solve K?

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

    There is a well known problem about finding a Hamiltonian path in an implicit tournament graph in $$$O(n \log n)$$$ (next to last GP of Gomel, I think). After you know the path, you are only interested in finding segments that are SCC. For that it's enough to find the leftmost outgoing edge from each vertex. Let's try all possibilities for 2 sports it should be better in, then we have queries "min on rectangle", solve them using scanline with segment tree.

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

    It can be proven that the SCC forms a total order. The SCC can be computed with Kosaraju's algorithm. To speed up, you can find an unvisited vertex with segment trees.

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

    For a tournament, node degrees determine connected components. Degrees can be found with inclusion exclusion (degree of person i = #people they beat in races 1, 2 + #people they beat in races 1, 3 + #people they beat in races 2, 3 — 2 * #people they beat in all races). To find these, use Fenwick trees for 2d cases, and your choice of 2d structure for 3d case.

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

I swear that J feels harder than A, C, E.

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

    Can you explain solution for E?

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

      The editorial is already published below and I found it hard to formulate solution in few words (I feel like there is a ton of indexing and variables and it would be total mess), so hopefully you can refer to the editorial.

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

Some late advertisements:

My favorite problem in this set was I (Organizing Colored Papers) by nong. He is not only a good problem setter but an indie game developer who created Teamfight Manager with his brother.

If you want to see competitive programmers in great success, you may want to support their work. But they don't need your help: Their work is already appreciated by Steam users, tons of pro gamers and streamers including DWG KIA ShowMaker and this Russian streamer. Just become a part of the great game!

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

How to solve C?

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

    For a tree, we add the edges in the non-increasing order of weights. Let's denote the component where $$$u$$$ is currently located is $$$A_u$$$. For an edge $$$(u,v,w)$$$, we have $$$v_T(u_0,v_0)=w (\forall u_0 \in A_u, v_0 \in A_v)$$$.

    Therefore, if two trees are in the same group, then for all weights $$$w$$$, there must be all components connected by edges with weight $$$w$$$ that are equivalent. Note that as long as the previous merges are the same, then in this round of merging, it is only necessary to ensure that the minimum values of all components are the same. You can use std::map to get a deterministic solution, or just choose a proper hash function.

    Code (hash)
»
3 года назад, # |
  Проголосовать: нравится +69 Проголосовать: не нравится

Editorials are now ready, enjoy!

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

Hello, where is the XXII Open Cup Schedule, or the next open cup contest?

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

Apparently in problem B in every test the number of Y-s in strings $$$S$$$ and $$$T$$$ is equal, even though it is not mentioned in the statement

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

Hyeong ko_osaga, can you share the test cases?

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

I'm misunderstanding K.

1 1

2 2

3 3

4 4

5 5

6 6

(Instead of this being the actual positions, let this be the physical orderings of the players, where the indices they are at are their actual places in the respective tournament)

From what I'm understanding, it won't have the edge (2,4) in it (or 2,3 into 3,4). If you call dfs(1), it looks like it'll result in calling dfs(6). Dfs(2) then calls into dfs(5), etc.

Then, when you do it backwards (with a min segtree this time), Dfs(6) calls dfs(1), etc. so you add the same edges.

So the edges in the graph are now (1,6), (2,5), (3,4).

This isn't right, so I know that there's a gap in my understanding, but I don't know what it is.

It kinda makes more sense if you don't do a DFS and process it in a specific order to add edges each time, but in this case it still requires the specific ordering of processing like, 6 5 1 2 (from top down) which is a bit sus since you don't know the correct ordering from the get go.

My approach was to use sets to process the highest value that the current index beats (and vice versa for the bottom up) but it fails in this test case:

5 6

1 1

6 5

2 3

4 4

3 2

where the edge (1,4) is missing even if you go both ways, so the editorial isn't talking about something like this either.

So what is it talking about? Evidently the editorial is straight over my head. What did I miss?