2025 ICPC Asia Seoul Regional Finals Solution Sketches

Disclaimer: This is an unofficial analysis of some possible ways to solve the problems of the 2025 ICPC Asia Seoul Regional Finals. They are not intended to give complete solutions, but rather to outline some approaches that can be used to solve the problems. If you find an error, please send me an email about it.

Live Solutions Presentation: https://www.youtube.com/live/5L4TCvByfCQ?t=1534s

M. Triple Fairness

My solution: 41 bytes.

Print 11 to nn, three times.

L. Segments

My solution: 289 bytes.

The answer is determined solely by the maximum of the left endpoints and the minimum of the right endpoints of the given line segments.

When computing the answer, remember to apply max⁡(0,⋅)\max(0, \cdot).

C. Bay

My solution: 752 bytes.

Treat the grid cells as vertices to form a rooted forest; then, via DFS, one can identify all edges that constitute the solution. Be sure to choose the vertices connected to the exterior of the grid as roots.

Alternatively, the problem can be solved by supporting "sum of cross products along a path" queries efficiently on the given tree TT. However, when applying Pick's theorem, the number of interior lattice points may not be zero.

I. Magic Door

My solution: 1,153 bytes.

Implement the rules exactly as specified. Within the gem-type encoding scheme defined in the problem, it helps to translate into a representation you are comfortable with—for example, distinguishing bombs by whether they are active or not. Treat a match-3 group as the union of matches whose length is exactly 33, and observe that repeatedly triggering activated bombs in the same row/column does not change the total time complexity, which simplifies implementation.

You must handle the problem's "simultaneously" requirement without missed or overwritten states. Using a "to-be-removed" bit flag (e.g., 1616) is effective.

Be careful not to early-terminate. For instance, you must continue processing even when there are activated bombs but no match-3 groups.

G. Extraterrestrial Creatures

My solution: 449 bytes.

Let f(t)f(t) denote the number of button presses required to make all creature numbers at least tt. Use binary search to find tt such that f(t)≤X<f(t+1)f(t) \le X < f(t + 1).

After raising all creature numbers to at least tt, apply one additional press to exactly (X−f(t))\left( X - f(t) \right) creatures whose values are exactly tt, chosen in increasing order of their IDs.

E. Clean Arrangements

My solution: 415 bytes.

For each vertex vv, let DvD_v be the minimum of "(cost of a clean arrangement of the subtree TvT_v) + (total length in which the edge joining vv to its parent overlaps the interval of TvT_v)".

Sort the child subtrees of vv in decreasing order of size and place them alternately to the left and right around vv; this minimizes DvD_v.

For the root, a slightly different expression is used for the objective, but the same placement strategy is optimal. The overall time complexity is O(n)O(n).

K. Quadrants

My solution: 1,189 bytes.

Fix a point and draw two perpendicular lines through it. Rotate these lines while maintaining the counts of points in each of the four quadrants. For convenience, call the lines the xx- and yy-axes. When another point lies on the +x+x ray, let the quadrant counts be c∗,∗c_{*, *}. Then the current state uniquely determines the [c+,+,c+,++c−,+)\left[ c_{+,+}, c_{+,+} + c_{-,+} \right)-quadrants in the region y>0y > 0 and the [c+,−,c+,−+c−,−)\left[ c_{+,-}, c_{+,-} + c_{-,-} \right)-quadrants in the region y<0y < 0.

D. Bookshelf

My solution: 451 bytes.

The initial positions are irrelevant. Let the width of book ii be AiA_i, and define w:=L−∑iAiw := L - \sum_i A_i. Any book can be swapped with a book of width ≤w\le w, while the relative order of two books with width >w> w is invariant.

Anchor the favorite book, and place all books with width >w> w to its left and right. The remaining books with width ≤w\le w can always be fitted into the leftover gaps.

It therefore suffices to test feasibility over all possible relative orderings between the favorite book and the other books with width >w> w.

F. CPEquivalence

My solution: 2,894 bytes.

Two arrays are CP-equivalent if and only if the max Cartesian trees constructed from them are isomorphic.

Let TT be the Cartesian tree of xx. For a subarray y[s⋯e]y[s \cdots e], define D[s,e],c,TvD_{[s, e], c, T_v} as the minimum possible value at the node of yy’s Cartesian tree corresponding to vv, over all ways to transform y[s⋯e]y[s \cdots e] with at most cc edits so that its Cartesian tree becomes isomorphic to the subtree TvT_v. A straightforward recursive recurrence follows, but its time complexity has degree 66. By leveraging the monotonicity of D∗D_{*} and applying a two-pointer technique with suitable precomputation, the degree can be reduced.

J. Mex Culpa

My solution: 2,539 bytes.

Define Ii:=[ai,ai+bi]I_i := \left[ a_i , a_i + b_i \right]. The inequality in the problem is equivalent to Ii∩Ij≠∅I_i \cap I_j \ne \emptyset.

First, identify all indices ii with fi=0f_i = 0. By repeatedly querying, for a given interval JJ, the smallest index ii such that Ii⊆JI_i \subseteq J, we can recover all entries with f∗=0f_{*} = 0.

After removing these, proceed analogously to find f∗=1,2,⋯f_{*} = 1, 2, \cdots in order.

A. Adventurer Dabi

My solution: 6,154 bytes.

This is a heavy-implementation problem. Implement the following in order:

  1. Move to an arbitrary cell adjacent to a wall.
  2. Discover all walls using the right-hand rule.
  3. Identify all teleport cells.
  4. Recover the full teleport pairs connectivity.
  5. From the key cell, travel to the treasure chest cell via a shortest path.

The following observation suffices: suppose Dabi is either at a known cell α\alpha or, via teleportation, at an unknown cell β\beta. To distinguish the two, starting from α\alpha, move—using only known cells—to a cell adjacent to a wall, then apply the right-hand rule. If no contradiction arises, it was α\alpha; if a contradiction occurs, it was β\beta. Since all moves are invertible, upon detecting a contradiction you can revert to a known state.

H. Fair Problemset

My solution: 743 bytes.

Let λn\lambda_n denote the number of Fair Problemset sequences of length 3n3n. Writing n=3q+rn = 3q + r and setting α:=q+δr,1\alpha := q + \delta_{r, 1} and β:=q+δr,2\beta := q + \delta_{r, 2}, we have

λn=(α!)3(β!)6Cn\lambda_n = (\alpha!)^3 (\beta!)^6 C_n

where CnC_n is the number of tuples (σ0,σ1,⋯ ,σn−1)∈Σ3n\left( \sigma_0, \sigma_1, \cdots, \sigma_{n - 1} \right) \in \Sigma_{3}^{n} satisfying

αδi,j+β(1−δi,j)=∣{k:σk(i)=j}∣\alpha \delta_{i, j} + \beta \left( 1 - \delta_{i, j} \right) = \left\lvert \left\{ k : \sigma_k (i) = j \right\} \right\rvert

Inspecting the six elements of Σ3\Sigma_3 yields

Cn=∑i=0q(nα−i;i;i;i;β−i;β−i)3C_n = \sum_{i = 0}^{q} {\binom{n}{\alpha - i ; i ; i ; i ; \beta - i ; \beta - i}}^{3}

Define Bq:=∑i=0q(qi)3B_q := \sum_{i = 0}^{q} {\binom{q}{i}}^{3}. For r=0r = 0, one obtains λn=n!(q!)6Bq\lambda_n = n! (q!)^{6} B_q. For r=1,2r = 1, 2, λn\lambda_n can be expressed similarly in terms of BqB_q and Bq+1B_{q + 1}.

B. Badge Relay

My solution: 3,538 bytes.

First, for n≥3n \ge 3 people with times t1≤t2≤⋯≤tnt_1 \le t_2 \le \cdots \le t_n, the answer is

(n−k−2)t1+(2k+1)t2+∑i=3n−2kti+∑i=0k−1tn−2i(n - k - 2) t_1 + (2k + 1) t_2 + \sum_{i = 3}^{n - 2k} t_i + \sum_{i = 0}^{k - 1} t_{n - 2i}

where m:=max⁡{j:tj≤2t2−t1}m := \max\left\{ j : t_j \le 2 t_2 - t_1 \right\} and k:=⌊(n−m)/2⌋k := \left\lfloor (n - m) / 2 \right\rfloor. A greedy strategy is optimal—this can be strongly supported by local testing, and proved rigorously in several ways. For an elegant approach, see: M. Jianu, M. Jianu, and S. A. Popescu, "A Combinatorial Solution for Bridge and Torch Problem," SN Operations Research Forum, 1(3), Article 21, Aug. 2020, doi: 10.1007/s43069-020-00022-3.

The final summation term is the trickiest to compute efficiently. After applying standard Mo's ordering to the query index intervals, maintain in a segment tree quantities such as "the sum of values that are the 11st, 33rd, 55th, ⋯\cdots largest." The overall time complexity is O(qnlog⁡n)O \left( q \sqrt{n} \log n \right).