Commentaries 2024
Commentaries 2024
Problems
ICPC 2024 ASIA YOKOHAMA REGIONAL JUDGE TEAM
(CHIEF: YUTARO YAMAGUCHI)
Easy Judges’ Estimation Difficult
ALL teams get ACs for Problems A and B!! Congratulations!!
ALL teams get at least 3 ACs!!! Congratulations!!!
A: Ribbon on the
Christmas Present
plan
Dyeing Process Diagram (DPD)
Consider the dyeing process using a layered diagram, DPD
◦ Dye a chunk of contiguous sections at once
◦ Dye from lighter to darker colors
created pattern
Key Observation
Any DPD will give the planned pattern if the surface is
correct for each section.
Our Problem:
Fill some of the hidden chunks and make an optimal DPD
?
?
hidden chunks
Approach
Fill the hidden chunk between surface chunks and merge
them into a single chunk.
left-open right-open
⚫double-open hidden chunk => must not be filled
gap => fill right-open => fill left-open => not fill
Resulting DPD
Algorithm
For each color, scan the planned pattern from left to right.
Start making a merged chunk when the color appear.
Stop merging when a lighter color appear or at the end of
the ribbon.
plan
O(n) Algorithm
Scan from left to right once while managing a stack of the
colors of “merging layers”
◦ stack top = next color: proceed to right
◦ stack top < next color: push next color, count++
◦ stack top > next color: pop
plan
O(n) Algorithm
Scan from left to right once while managing a stack of the
colors of “merging layers”
◦ stack top = next color: proceed to right
◦ stack top < next color: push next color, count++
◦ stack top > next color: pop
plan
B: The Sparsest
Number in Between
PROPOSER: ETSUYA SHIBAYAMA
AUTHOR: ETSUYA SHIBAYAMA
Problem Descriptions
Input: two positive integers 𝑎 and 𝑏
(𝑎 ≤ 𝑏)
Smallest
Challenge: find the sparsest integer
between 𝑎 and 𝑏, inclusive
Definition: 𝑥 is sparser than 𝑦 if and only if the
binary representation of 𝑥 has a smaller
number of 1’s than that of 𝑦
Example
When 10 and 15 are given
Decimal Binary # of 1’s
The Answer
10 1010 2
11 1011 3
The Integers 12 1100 2
in Between Sparsest
13 1101 3
14 1110 3
15 1111 4
Solution
Since 𝑎 and 𝑏 can be large (up to 1018 ), a naïve
search like the following does not work
for (long long i = a; i <= b; i++) {
// do some work
}
Dijkstra’s algorithm!
D: Tree Generators
PROPOSER: MITSURU KUSUMOTO
AUTHOR: MITSURU KUSUMOTO
Parsing!!
Syntax is
E ::= 1 | (E E)
‘1’ = Single vertex
1
It’s a tree
‘(E1 E2)’ = Add one edge randomly
between two trees
generated by E1 & E2
62
2
4 ? 51
73
1
3
Generated from E1 Generated from E2
(labels are increased)
Input: Two expressions
((11)(11)) ((11)1)
1 1 1 1 1 1 1
1 2 3 4 5 6 7
Example (Sample 3)
E=(((11)(11))((11)1))
Black node = single edge addition step
Triples are shown below the node (1,4,7)
((11)(11)) ((11)1)
1 2 3 4 5 6 7
This represents adding edges from
• [1,4]x[5,7]
Example (Sample 3) • [1,2]x[3,4]
• (1,2)
• (3,4)
E=(((11)(11))((11)1))
• (5,6)
Black node = single edge addition step • [5,6]x{7}
Triples are shown below the node (1,4,7)
((11)(11)) ((11)1)
1 2 3 4 5 6 7
Trees generated (2)
So, what kind of trees can be generated?
Assume that generated trees contains n vertices.
After parsing an expression, you can obtain triples (ai, bi, ci)
(i=1,...,n-1) such that
((11)(11)) ((11)1)
2 6
(11) (1,4) (11) (11) (5,7)
1 3 5
(1,2) (3,4) (5,6)
1 1 1 1 1 1 1
1 2 3 4 5 6 7
Solution
Suppose that pairs (a’i, c’i) are obtained from the other
expression.
Then, the solution is
𝑛−1
5 . P . .
-
# # - # .
𝑛
. . . * 4
5 *
. 3 # # .
3 4
1 ≤ 𝑛, 𝑚 ≤ 50.
Node types
Following nodes are provided.
• Printer (P) : the root node.
• Digit (0-9) : a leaf node with a value. P (root) → print “7”
𝐴 𝐵 𝐴 𝐵 𝐴 𝐵 𝐴 𝐵
Solution
Traverse the tree from the printer recursively.
•For an operator cell,
• Traverse a subtree of one connection and memorize the result.
• Traverse the other connection and apply the operator’s calculation.
↑ ↓
↑ ↓
↑ ↓ ←
↑ ← ← ←
Original idea
→ → ↓
↑ ↓
↑ ↓
↑ ↓ ←
↑ ← ← ←
Solution
Interactive Problem
Solution
Interactive Problem
As usual:
Binary Search
←←
→↓
→
→
S
←←
→↓
→
→
S
←←
𝑂(𝑁 log 𝑁)
4𝑁 = 8000 x log 𝑁 = 11 =
88000 queries
AC …. ?
𝑂(𝑁 log 𝑁) =
4𝑁 = 8000 x log 𝑁 = 11 =
𝑂 𝑁 query
Full editorial(1/3)
The core idea is that for a continuous region with a grid, it is possible to
determine whether the goal (G) is included in the region without
examining every cell. To know this, it is sufficient to count the number
of times the path "enters" and "exits" the region. This can be done by
knowing only the boundary parts, that is, the cells in the region that
touch the outside and the cells outside that touch the region.
Distance = 8 (Even)
Grid Graph Is Bipartite
Let input graph 𝐺 be represented as 𝑈, 𝑉, 𝐸 .
For simplicity, assume 𝑈 ≤ 𝑉 . 3
2
1 2 3 1
4
5
4 5 6
6
7
7 8 9 8
9
𝑈 = 2, 4, 6, 8
𝑉 = 3, 1, 5, 7, 9
𝐸 = all edges
Rephrased Constraint
Distances between all pairs of leaves are even.
⇔ Either 𝑈 or 𝑉 does not contain any leaves.
3 3
2 2
1 1
4 4
5 5
6 6
7 7
8 8
9 9
𝑈 𝑉 𝑈 has no leaves
Cases of 𝑈 = 𝑉
When 𝑈 = 𝑉 , always infeasible!
∵) Suppose 𝐺 = 𝑈, 𝑉, 𝐸 has no leaves in 𝑈 and satisfies
𝑈 = 𝑉 . Clearly, 𝐸 ≥ 2 𝑈 = 𝑈 + 𝑉 , which implies 𝐺 ′
contains cycle(s). ■
6 2 14 4 3 2 5 1 7
gcd(6, 4) = 2 gcd(14, 7) = 7
Solution
• Common divisor
▪ ⇨ A value appears twice in the interval as a divisor.
• Read sequence from left to right
• Manage the rightmost and second rightmost indices
6 2 14 4 3 2 5 1 -
d 1 2 3 4 5 6 7 ...
f(d) 8 6 5 4 7 -1 3
s(d) 7 4 1 -1 -1 -1 -1
Solution
• Common divisor
▪ ⇨ A value appears twice in the interval as a divisor.
• Read sequence from left
• Manage the rightmost and second rightmost indices
6 2 14 4 3 2 5 1 7
Update d=1, 7
d 1 2 3 4 5 6 7 ...
f(d) 9 6 5 4 7 -1 9
s(d) 8 4 1 -1 -1 -1 3
Solution
• When i-th element is updated, solve all queries that have R=i
▪ f(d) ≦ R is satisfied for all d
• If L ≦ s(d) is satisfied, then d is a common divisor in the interval
▪ Find argmaxd { L ≦ s(d) }
6 2 14 4 3 2 5 1 7
d 1 2 3 4 5 6 7 ...
f(d) 9 6 5 4 7 -1 9
s(d) 8 4 1 -1 -1 -1 3
Solution
• Build a segment tree (range maximum query) for s(d)
• Binary search on segment tree
6 2 14 4 3 2 5 1 7
d 1 2 3 4 5 6 7 ...
s(d) 8 4 1 -1 -1 -1 3
Summary
•Group intervals by R
•Read the sequence from left to right
•Update second rightmost indices of divisors, and the
segment tree
•Binary search with the condition { L ≦ s(d) } on the tree
•Maximum d is the greatest GCD
J: Mixing Solutions
PROPOSER: NAOKI MARUMO
AUTHOR: NAOKI MARUMO
+ KOHEI MORITA
Problem
Mix parts of 𝑛 solutions to make a new solution
Given:
• amount
of each prepared solution
• range of concentration
• amount
of the mixed solution
• target concentration 𝑐
• 𝑥, 𝑦 ≔ 𝑐 − 𝑙, 𝑟 − 𝑐
• 𝑥, 𝑦 also moves over a convex polygon, 𝑃
𝑦 𝑦 𝑦
𝑦=𝑥 𝑦=𝑥 𝑦=𝑥
𝑃
𝑃
𝑥 𝑃 𝑥 𝑥
min max 𝑥, 𝑦
𝑥,𝑦 ∈𝑃
optimal 𝑥, 𝑦 𝑃
𝑥
110 0 1 1
1 01 1 1
0 1 1 1 1
The best buddy => word with the most 1s among
supersets of the complement!
1 1 1
0 1 1 1 0 1 1 1 0
0 1 1
0 0 1 0 1 0 1 0 0
0 0 0
Solution
The diagram can be preprocessed in O(M・2M) time
dynamic programming. O(N + M・2M) time in total.
dp[bitpat] := 111
the best word in input
among supersets of bitpat 0 1 1 1 0 1 1 1 0
0 1 1 1 0 1 1 1 0
1 1 1
0 0 1 0 1 0 1 0 0
0 0 0
L: Peculiar Protocol
PROPOSER: KAZUHIRO INABA
AUTHOR: SOH KUMABE
Problem
Given an array 𝑎1 , … 𝑎𝑛 (𝑛 ≤ 500) and integers 𝑑, 𝑟
We can repeat following:
◦ Take interval [𝑝, 𝑞] with 𝑎𝑝 + ⋯ + 𝑎𝑞 = 𝑘𝑑 + 𝑟 for some integer 𝑘
◦ Remove these elements and squeeze the sequence
∑𝑎𝑖 −𝑟⋅#𝑜𝑝𝑒𝑟𝑎𝑡𝑖𝑜𝑛𝑠
Proof: total 𝑘’s =
𝑑
Subproblem
Minimize the number of operations,
assuming we remove all elements