ko_osaga's blog

By ko_osaga, history, 6 weeks ago, In English
 
 
 
 
  • Vote: I like it
  • +188
  • Vote: I do not like it

»
6 weeks ago, # |
  Vote: I like it +53 Vote: I do not like it

How to solve G, M?

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it +47 Vote: I do not like it

    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.

»
6 weeks ago, # |
  Vote: I like it +44 Vote: I do not like it

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.

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it +50 Vote: I do not like it

    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
»
6 weeks ago, # |
  Vote: I like it +80 Vote: I do not like it

Thank you for the participation!

Problems were prepared by

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

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it +10 Vote: I do not like it

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

»
6 weeks ago, # |
  Vote: I like it +22 Vote: I do not like it

How to solve A?

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it +17 Vote: I do not like it

    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

    • »
      »
      »
      6 weeks ago, # ^ |
        Vote: I like it +1 Vote: I do not like it

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

      • »
        »
        »
        »
        6 weeks ago, # ^ |
        Rev. 2   Vote: I like it +18 Vote: I do not like it

        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.

»
6 weeks ago, # |
  Vote: I like it +11 Vote: I do not like it

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.

  • »
    »
    6 weeks ago, # ^ |
    Rev. 3   Vote: I like it +8 Vote: I do not like it

    Due to unusual time limit I suppose it was intended. By the way there exists linear solution.

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it +10 Vote: I do not like it

    Yes. Model solution is $$$O(n)$$$, and it passes TL very leniently.

»
6 weeks ago, # |
  Vote: I like it +10 Vote: I do not like it

Any hints for L and F? :)

  • »
    »
    6 weeks ago, # ^ |
    Rev. 2   Vote: I like it +20 Vote: I do not like it

    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.

    • »
      »
      »
      6 weeks ago, # ^ |
        Vote: I like it +8 Vote: I do not like it

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

      • »
        »
        »
        »
        6 weeks ago, # ^ |
          Vote: I like it +8 Vote: I do not like it

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

        • »
          »
          »
          »
          »
          6 weeks ago, # ^ |
            Vote: I like it +8 Vote: I do not like it

          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.

          • »
            »
            »
            »
            »
            »
            6 weeks ago, # ^ |
            Rev. 2   Vote: I like it +8 Vote: I do not like it

            L(2) -> R(2) -> L(1) -> R(1) is a single path?

            (Edit: Yes, the edge is not added from $$$t$$$ to $$$s$$$. It is added from sink to source. My bad)

          • »
            »
            »
            »
            »
            »
            6 weeks ago, # ^ |
              Vote: I like it +21 Vote: I do not like it

            • »
              »
              »
              »
              »
              »
              »
              6 weeks ago, # ^ |
                Vote: I like it +11 Vote: I do not like it

              Okey, I didn't got capacity of T -> S edge correctly. But my solution gets TL anyway.

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it +20 Vote: I do not like it

    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
»
6 weeks ago, # |
  Vote: I like it +26 Vote: I do not like it

How to solve K?

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it +55 Vote: I do not like it

    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.

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it +34 Vote: I do not like it

    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.

    • »
      »
      »
      6 weeks ago, # ^ |
        Vote: I like it +18 Vote: I do not like it

      Thanks. Cute transition to SCCs in tournament graphs.

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it +44 Vote: I do not like it

    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.

»
6 weeks ago, # |
  Vote: I like it +23 Vote: I do not like it

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

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    Can you explain solution for E?

    • »
      »
      »
      5 weeks ago, # ^ |
        Vote: I like it +8 Vote: I do not like it

      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.

»
6 weeks ago, # |
  Vote: I like it +62 Vote: I do not like it

Some late advertisements:

My favorite problem in this set was I (Organizing Colored Papers) by no_ng. 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!

»
6 weeks ago, # |
  Vote: I like it +23 Vote: I do not like it

How to solve C?

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it +50 Vote: I do not like it

    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)
»
5 weeks ago, # |
  Vote: I like it +69 Vote: I do not like it

Editorials are now ready, enjoy!

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
5 weeks ago, # |
  Vote: I like it +10 Vote: I do not like it

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

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    It is translator's mistake (who is me). Sorry!

»
5 weeks ago, # |
  Vote: I like it +8 Vote: I do not like it

Hyeong ko_osaga, can you share the test cases?