**Update (2021.10.28):** Editorial, Division 1 Gym, Division 2 Gym are prepared.

Hello!

XXII Open Cup. Grand Prix of Korea will be held in 2021/10/24 Sunday, 17:00 KST (UTC+9).

For external accounts, the contest is ready now.

List of relevant previous contests:

- XVIII Open Cup. GP of Korea
- KAIST RUN Spring Contest 2018
- XIX Open Cup. GP of Korea
- XIX Open Cup. GP of Daejeon
- XX Open Cup. GP of Korea
- 2020-2021 Summer Petrozavodsk Camp, Day 6: Korean Contest
- XXI Open Cup. GP of Korea
- XXI Open Cup. GP of Suwon

Enjoy!

How to solve G, M?

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.

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.

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

CodeWow, great solution. Thank you Qingyu !

Thank you for the participation!

Problems were prepared by

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

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

How to solve A?

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

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

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.

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.

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

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

Any hints for L and F? :)

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.

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

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

Consider test

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.

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)

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

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$$$:

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 tricksHow to solve K?

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.

I see, thanks.

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.

Thanks. Cute transition to SCCs in tournament graphs.

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.

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

Can you explain solution for E?

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.

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!

How to solve C?

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)Editorials are now ready, enjoy!

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

arthurconmy here . Next round is on 7 November.

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

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

Hyeong ko_osaga, can you share the test cases?

You can find some of them (not all) in https://drive.google.com/drive/u/0/mobile/folders/1-BG9lmWvPeN4nayQ13YDHOpUvPWPdA7A?usp=sharing.

Thank you! 감사합니다

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?