0% found this document useful (0 votes)
12 views111 pages

Commentaries 2024

The document outlines the problems presented at the ICPC 2024 Asia Yokohama Regional, including solutions and algorithms for each problem. Key problems include dyeing a ribbon with minimal steps, finding the sparsest integer between two numbers, minimizing the cost of spanning trees in a graph, and generating trees from expressions. Each problem is accompanied by proposed solutions and algorithms, emphasizing efficient approaches to complex computational challenges.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views111 pages

Commentaries 2024

The document outlines the problems presented at the ICPC 2024 Asia Yokohama Regional, including solutions and algorithms for each problem. Key problems include dyeing a ribbon with minimal steps, finding the sparsest integer between two numbers, minimizing the cost of spanning trees in a graph, and generating trees from expressions. Each problem is accompanied by proposed solutions and algorithms, emphasizing efficient approaches to complex computational challenges.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 111

Commentaries on

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

PROPOSER: KAZUHIRO INABA


AUTHOR: TOMOHARU UGAWA
Problem
Dye white ribbon and make the “planned pattern.”
◦ Contiguous segments can be dyed in a single step
◦ A darker color masks lighter color
Compute the minimum possible number of dyeing steps
init

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

Find an optimal DPD


◦ DPD with the fewest chunks of continuous sections
DPD (not optimal)

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.

fill this gap


surface chunk
Cases
⚫hidden chunk between chunks => must be filled

⚫half-open hidden chunk => arbitrary

left-open right-open
⚫double-open hidden chunk => must not be filled

Typical submitted wrong


answers filled this case
One of the Solutions
Fill hidden chunks that follow to surface chunks.

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
}

Proper division of cases, like a mathematical


proof, can help you
Division of Cases
Case 1: 𝒂 is a power of two (𝟐𝒏 )
The answer is 𝒂 itself
𝑎’s binary rep. has just a single 1, and thus sparsest and
smallest
Decimal Binary
a 8 1000
answer 8 1000
b 19 10011

[Hereafter, we assume that 𝑎 is not a power of two]


Division of Cases
Case 2a: the binary rep. of 𝒂 is shorter than that of 𝒃
The answer is the smallest power of two greater than 𝒂
Suppose for instance that 14 and 33 are given
Decimal Binary
a 14 1110
answer 16 10000
b 33 100001

Obviously, 14 ≤ 16(= 24 ) ≤ 33, and 16 is the smallest


among the sparsest
Division of Cases
Case 2b: the binary reps. of 𝒂 and 𝒃 are of the same length
The binary rep. of the answer must share the same
common prefix as 𝒂’s and 𝒃’s
The rest of the binary rep. of the answer can be found in a
similar manner as case 1 or 2a
Unless 𝑎 = 𝑏, the rest parts of the 𝑎’s and 𝑏’s binary reps.
always start with 0 and 1, respectively.
Decimal Binary
Common prefix Suffix
a 43 101 011
answer 44 101 100
b 47 101 111
How to deal with binary reps.
You may use bit operations
You may also first convert numbers to strings and then use
string operations
C: Omnes Viae
Yokohamam Ducunt?
PROPOSER: MASATOSHI KITAGAWA
AUTHOR: MASATOSHI KITAGAWA
Problem
Given a weighted undirected graph 𝐺 = 𝑉, 𝐸 .
◦ 𝑝𝑣 : weight of a vertex 𝑣 (significance value)
◦ 𝑞𝑒 : weight of an edge 𝑒 (vulnerability)
◦ 𝑠 ∈ 𝐺: Yokohama

Minimize the cost (total risk severity) of spanning trees of 𝐺.


Problem(Cost)
For a spanning tree 𝑇 = 𝑉, 𝐸𝑇 of 𝐺,
cost of 𝑇 ≔ ෍ 𝑞𝑒 ෍ 𝑝𝑣 .
𝑒∈𝐸𝑇 𝑣

The second sum is taken over all 𝑣 ∈ 𝑉 inaccessible from 𝑠 in 𝑇 −


𝑒 .
Problem(Cost)
For a spanning tree 𝑇 = 𝑉, 𝐸𝑇 of 𝐺,
cost of 𝑇 ≔ ෍ 𝑞𝑒 ෍ 𝑝𝑣 .
𝑒∈𝐸𝑇 𝑣

The second sum is taken over all 𝑣 ∈ 𝑉 inaccessible from 𝑠 in 𝑇 −


𝑒 .

Minimum spanning tree problem?


Problem(Cost)
For a spanning tree 𝑇 = 𝑉, 𝐸𝑇 of 𝐺,
cost of 𝑇 ≔ ෍ 𝑞𝑒 ෍ 𝑝𝑣 .
𝑒∈𝐸𝑇 𝑣

The second sum is taken over all 𝑣 ∈ 𝑉 inaccessible from 𝑠 in 𝑇 −


𝑒 .

Minimum spanning tree problem?


No!
The cost of 𝑒 depends on 𝑇.
Rewrite Cost
cost of 𝑇 ≔ ෍ 𝑞𝑒 ෍ 𝑝𝑣 .
𝑒∈𝐸𝑇 𝑣

Swapping the two sums,


cost of 𝑇 = ෍ 𝑝𝑣 ෍ 𝑞𝑒 .
𝑣∈𝑉 𝑒
The second sum is taken over all 𝑒 in the 𝑠−𝑣 path in 𝑇.
Rewrite Cost
cost of 𝑇 ≔ ෍ 𝑞𝑒 ෍ 𝑝𝑣 .
𝑒∈𝐸𝑇 𝑣

Swapping the two sums,


cost of 𝑇 = ෍ 𝑝𝑣 ෍ 𝑞𝑒 .
𝑣∈𝑉 𝑒
The second sum is taken over all 𝑒 in the 𝑠−𝑣 path in 𝑇.
cost of 𝑇 = ෍ 𝑝𝑣 distance from 𝑠 to 𝑣 in 𝑇 .
𝑣∈𝑉
Solution
cost of 𝑇 = ෍ 𝑝𝑣 distance from 𝑠 to 𝑣 in 𝑇
𝑣∈𝑉
This cost is minimized when 𝑇 is a shortest-path tree rooted
at 𝑠.
Solution
cost of 𝑇 = ෍ 𝑝𝑣 distance from 𝑠 to 𝑣 in 𝑇
𝑣∈𝑉
This cost is minimized when 𝑇 is a shortest-path tree rooted
at 𝑠.

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

Output: # of trees generated from them


in common modulo 998244353

Solve in linear time.


Trees generated
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

Each edge is randomly chosen from [ai, bi] x [bi+1, ci]


Example (Sample 3)
E=(((11)(11))((11)1))

((11)(11)) ((11)1)

(11) (11) (11)

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)

(11) (1,2,4) (11) (11) (5,6,7)

(1,1,2) (3,3,4) (5,5,6)


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

(11) (1,2,4) (11) (11) (5,6,7)

(1,1,2) (3,3,4) (5,5,6)


1 1 1 1 1 1 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

Each edge is randomly chosen from [ai, bi] x [bi+1, ci]

Values bi appears just once in the triples; Let’s simplify this:

Each edge is randomly chosen from [ai, i] x [i+1, ci]


This is like, the gap between i and i+1 is generating an edge.
Example revised
E=(((11)(11))((11)1))
Black node = single edge addition step 4
(ai, ci) is shown below (1,7)

((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

ෑ 𝑖 − max 𝑎𝑖 , 𝑎′𝑖 + 1 × min 𝑐𝑖 , 𝑐𝑖′ − 𝑖 .


𝑖=1

The remaining part is the proof for this.


Correspondence (1)
Suppose that a tree is generated from E.
For each edge, can we identify which gap generated it?
Answer: We can uniquely identify.
Why? Traversing the generation steps in the parsed tree
from top to bottom will give one-to-one correspondence
between edges and generations.
Example revised (2) There can be only one
edge between [1,4]x[5,7].
E=(((11)(11))((11)1))
In this example, it’s (3,5).
After removing (3,5), we
Black node = single edge addition step 4 can recursively do this
(ai, ci) is shown below (1,7) identification process.
((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
Generated
tree → 1 2 3 4 5 6 7
Correspondence (2)
Now, suppose that a tree is generated from both E1 and E2.
For an edge (j, k), if
(j, k) is generated from the gap between i and i+1 in E1, and
(j, k) is generated from the gap between i’ and i’+1 in E2,

then, we denote as π(i) = i’.


The mapping π is bijective. We can show that π must be an
identity function. This justifies the solution mentioned.
Proof by infinite decent
Suppose that π is not an identity. This means there exists a
pair i≠j s.t. j=π(i).
From some observation, ai ≤ j < ci.
For k=1,...,n-1, let f(k) = ck - ak.
Then, f(i) = ci - ai > f(j) holds. If we continue this, we have
f(i) > f(j) > f(j’) > f(j’) > ... for j’=π(j), j’’=π(j’), ...

However, since π is bijective, this deduction eventually


results in f(i) > f(i). This is contradiction. Thus, π is identity.
E: E-Circuit Is
Now on Sale!
PROPOSER: SHINYA SHIROSHITA
AUTHOR: SHINYA SHIROSHITA
Problem
You are given a tree of a mathematical formula embedded
in a grid space.
Your task is to calculate the result of the formula.
𝑚
P (root)

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”

• Operator (+-*/) : a node applying an 7


arithmetic operation. -

(“#” forms edges connecting nodes.) 12


5 *
max{𝐴, 𝐵}
𝐴+𝐵 𝐴−𝐵 𝐴×𝐵 min{𝐴, 𝐵}
3 4
+ - * /

𝐴 𝐵 𝐴 𝐵 𝐴 𝐵 𝐴 𝐵
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.

Be careful about careless mistakes! 20 min


Overflow, out of range, infinite loop, … 20 min
20 min
20 mi

It is wasteful to get penalties by


careless mistakes.
F: The Farthest Point
PROPOSER: F.YAMAGUCHI
AUTHOR: F.YAMAGUCHI
Problem
Given: the size (edge lengths) of a rectangular cuboid
Write a program which computes the distance from a vertex
to its farthest point on the surface of the cuboid.
the farthest point
the opposite vertex

the starting vertex


Core Idea
an alias of
an alias of
the starting
the starting vertex
vertex

the opposite Any path from the farthest point to the


vertex starting vertex has the same distance.
The farthest point is the circumcenter of the
triangle consists of the starting vertex and
its two aliases on a net.
Calculate the length of the longest path to
the candidate among sufficient net settings.
the starting vertex
Note that...
For a candidate of the farthest point,
the segment between the starting
vertex and the candidate point should
not cross any edge of the net.

Distance is the length of


the shortest path among all
possible paths.

The distance from the


starting point is not a
convex function.
G: Beyond the
Former Exploer
PROPOSER: KOHEI MORITA
AUTHOR: KOHEI MORITA
+ MITSURU KUSUMOTO
Only
30000
Query
→ → ↓

↑ ↓

↑ ↓

↑ ↓ ←

↑ ← ← ←
Original idea
→ → ↓

↑ ↓

↑ ↓

↑ ↓ ←

↑ ← ← ←
Solution
Interactive Problem
Solution
Interactive Problem

As usual:
Binary Search
←←

→↓


S

←←

Compare (left →) vs (right ←)


Left region has G(goal)
←←

→↓


S

←←

𝑂(𝑁 log 𝑁)

Compare (left →) vs (right ←)


Left region has G(goal)
AC …. ?
𝑂(𝑁 log 𝑁) =

4𝑁 = 8000 x log 𝑁 = 11 =

88000 queries
AC …. ?
𝑂(𝑁 log 𝑁) =

4𝑁 = 8000 x log 𝑁 = 11 =

88000 queries Only


30000
Query
AC …. ?
𝑂(𝑁 log 𝑁) =
𝑂(𝑁 log 𝑁) is
4𝑁 = 8000 x log 𝑁 = 11 =
insufficient
88000 queries Only
30000
Query
Vertical
→ Horizontal
→ Vertical
→ Horizontal
:
Vertical
→ Horizontal
→ Vertical
→ Horizontal
:

𝑂 𝑁 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.

Based on this consideration, for example, by examining all the cells in


the 𝑖-th and 𝑖 + 1-th columns, it is possible to determine whether the
goal is on the left or right.
Therefore, by performing a binary search on the range of columns
where the goal might exist, it is possible to identify the goal with
𝑂(𝑁 log 𝑁) queries. However, since it is necessary to examine 4𝑁 cells
in one step of the search, this approach is hard to get accept in terms of
the number of queries.
Full editorial(2/3)
A further improvement is to reduce the number of queries by searching in the order of (split the
region vertical) → horizontal → vertical → horizontal → ... like a KD-tree. The logic is as follows:
- First, examine the central 2 columns (4𝑁 cells) to determine whether the goal is on the left or
right.
- Examine the central 2 rows (2𝑁 cells) to determine whether the goal is up or down. This will
make the region where the goal might exist a square of 𝑁 × 𝑁 (the size will vary by ±1
depending on which of the four sides is chosen).
- Examine the central 2 columns (2𝑁 cells) to determine whether the goal is on the left or right.
- Examine the central 2 rows (𝑁 cells) to determine whether the goal is up or down.
- ... and repeat this search.
Since the number of cells required for the search is halved every 2 steps, the order of the
number of queries for the entire search improves to O(𝑁). Specifically, estimating the constants,
the number of cells required for the search is 4𝑁 + 2𝑁 + 2𝑁 + 𝑁 + 𝑁 + ⋯ = 12𝑁 cells, so
there is enough margin against the query limit of 30000.
Full editorial(3/3)
The next consideration is how to move. In fact, there is a solution that requires only O(1) extra moves per step,
that is, a total of 12𝑁 + 𝑂(log 𝑁) queries (Bonus), but it is assumed to be complicated to implement.
Since there is a margin of about 3N queries, it is desired to simplify the implementation as appropriate.
Various approaches can be considered, but one example is to assume that "the starting point of each step is at
the center of the region." In other words,
- First, examine the central 2 columns (4N cells) to determine whether the goal is on the left or right.
- Move to the center of the new region with N/2 queries.
- Examine the central 2 rows (2N cells) to determine whether the goal is up or down.
- Move to the center of the new region with N/2 queries.
- Examine the central 2 columns (2N cells) to determine whether the goal is on the left or right.
- Move to the center of the new region with N/4 queries.
- Examine the central 2 rows (N cells) to determine whether the goal is up or down.
- Move to the center of the new region with N/4 queries.
- ... and repeat this search.
With this approach, the extra moves increase by about 2N cells, but this is within the acceptable range.
H: Remodeling the
Dungeon 2
PROPOSER: YUTARO YAMAGUCHI
AUTHOR: RYOTARO SATO
Problem Statement
Given connected graph on ℎ × 𝑤 2D grid (ℎ, 𝑤 ≤ 400),
find subset of edges (or report it is impossible) such that:
• All vertices and selected edges form a tree.
• Distances between all pair of leaves are even.
Input Output

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

Hereafter, we assume 𝑈 < 𝑉 and 𝑈 has no leaves.


Updated Problem Statement
Given 𝐺 = 𝑈, 𝑉, 𝐸 𝑈 < 𝑉 , find 𝐸 ′ ⊂ 𝐸 such that:
• Each vertex in 𝑈 has two (or more) adjacent edges in 𝐸 ′
• 𝑈, 𝑉, 𝐸′ is a tree graph
Then, how to assign two edges for each vertex in 𝑈 without
making any cycles?
Note: This is typical matroid intersection problem, but naive
implementations of general MI instances are too slow for
prepared testcases!
Step 1. Maximum Matching
First, find maximum matching of 𝑈, 𝑉, 𝐸 .
1.5
Can be done by Hopcroft–Karp algorithm, 𝑂 𝐸 .
If size of matching < 𝑈 , infeasible!
3
2
1
4
𝑈 5 𝑉
6
7
8
9
Step 2. DFS
Run DFS on the directed graph, from all vertices in 𝑉 NOT
used in matching. Edges’ directions:
• NOT used in matching: 𝑉-to-𝑈 Each vertex has
• USED in matching: 𝑈-to-𝑉 two (in & out) edges
3 3 3
2 2 2
1 1 1
4 4 4
𝑈 5 𝑉 5 5
6 Convert to 6 DFS 6
7 7 7
Directed Graph
8 8 Start 8
9 9 9
Infeasible Cases
If some vertices are unreachable by DFS, infeasible!
∵) 𝑈 ′ ⊂ 𝑈 : set of all unreachable vertices.
𝑉 ′ ⊂ 𝑉 : set of all vertices adjacent to any vertex in 𝑈 ′ .
We can prove 𝑉 ′ ≤ 𝑈 ′ (Exercise), which means it is
impossible to choose 2 𝑈 ′ edges adjacent to 𝑈 ′ without
making any cycle. ■ 1 1
1 2 3 2 2
3 3
4 4 𝑉′
4 5 6 5 5
6
7 𝑈′ 6 7
7
𝑈 𝑉 Unreachable
Step 3. Make Graph Connected
We obtained the DFS forest that satisfies degree constraints.
Finally, do not forget to adopt additional edges to make
graph connected!
1.5
Overall complexity: 𝑂 ℎ𝑤 (bounded by finding max
matching).
I: Greatest of the
Greatest Common
Divisors
PROPOSER: TOMOHIRO OKA
AUTHOR: TOMOHIRO OKA
Problem
Given positive integer sequence and intervals.
Choose a pair of 2 indices from the interval (L, R), consider
the GCD of the values.
Output the greatest of the GCD among all pairs from the
interval.

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

Binary search when L=3 ⇨ answer d=7


8
8 3 ...
8 -1 3 3

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 𝑐

Minimize: Max. Error max 𝑥 − 𝑐


𝑥∈ 𝑙,𝑟

𝑙, 𝑟 : concentration range of the mixed solution


Reformulate 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 𝑐

Minimize: Max. Error max 𝑥 − 𝑐 = max 𝑐 − 𝑙, 𝑟 − 𝑐


𝑥∈ 𝑙,𝑟

𝑙, 𝑟 : concentration range of the mixed solution


Reformulate Problem
We want to solve
min max 𝑐 − 𝑙, 𝑟 − 𝑐
𝑙, 𝑟
but what range does 𝑙, 𝑟 ∈ ℝ2 move over?

𝑙, 𝑟 : concentration range of the mixed solution


Reformulate Problem
We want to solve
min max 𝑐 − 𝑙, 𝑟 − 𝑐
𝑙, 𝑟
but what range does 𝑙, 𝑟 ∈ ℝ2 move over?

The set of possible 𝑙, 𝑟 ∈ ℝ2 is a convex polygon!


➢ Note: A convex combination of two valid mixings is also valid

𝑙, 𝑟 : concentration range of the mixed solution


Reformulate Problem
We want to solve
min max 𝑐 − 𝑙, 𝑟 − 𝑐 = min max 𝑥, 𝑦
𝑙, 𝑟 𝑥,𝑦 ∈𝑃

• 𝑥, 𝑦 ≔ 𝑐 − 𝑙, 𝑟 − 𝑐
• 𝑥, 𝑦 also moves over a convex polygon, 𝑃

𝑙, 𝑟 : concentration range of the mixed solution


Three cases
min max 𝑥, 𝑦
𝑥,𝑦 ∈𝑃

𝑦 𝑦 𝑦
𝑦=𝑥 𝑦=𝑥 𝑦=𝑥
𝑃
𝑃

𝑥 𝑃 𝑥 𝑥

Most interesting case


Outline of solution
𝑦 𝑦=𝑥

min max 𝑥, 𝑦
𝑥,𝑦 ∈𝑃

optimal 𝑥, 𝑦 𝑃
𝑥

• The red point can be easily obtained from two adjacent


green vertices

• Compute the green vertices by binary search


Compute green vertices
𝑦 𝑦=𝑥

• Each vertex is the point minimizing


the inner product with a vector
𝑃
• Given a vector, the vertex that 𝑥
minimizes the inner product can be
computed greedily in O 𝑛 log 𝑛 time

• Green vertices can be computed by binary searching


the vectors
Details
For the binary search, we can
• precompute Θ 𝑛2 candidate vectors and sort them
→ O 𝑛2 log 𝑛 solution

1 𝐵−1 2 𝐵−2 𝐵−1 1


• use , , , ,…, , with 𝐵 = Θ 𝑀2
𝐵 𝐵 𝐵 𝐵 𝐵 𝐵
→ O 𝑛 log 𝑛 log 𝑀 solution

Problem J can also be solved using the minimax theorem


or LP duality, without relying on geometric insights
K: Scheduling Two
Meetings
PROPOSER: KAZUHIRO INABA
AUTHOR: KAZUHIRO INABA
Problem
M ≦ 20

0 0 1 Given many M-bits


words, find a pair
1 1 0 (a,b) such that
N
≦ 1 0 1 a|b = 11…11
2*105 a&b has the most 1s
0 1 1
Solution
For each word, find the best buddy!
Naïve Θ(N2) loop will hit TLE, though…
00 1 110 1 01 0 11
00 1 0

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

dp[bitpat] 001 010 100


= max(dp[bitpat|1<<i], …)
for i in 0 .. M-1
0 0 0
The corner case, that many
teams were trapped
1 1 1

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

Maximize the total of 𝑘’s


Subproblem
Given an array 𝑎1 , … 𝑎𝑛 (𝑛 ≤ 500) and integers 𝑑, 𝑟
We can repeat following:
◦ Take interval [𝑝, 𝑞] with 𝑎𝑝 + ⋯ + 𝑎𝑞 = 𝑘𝑑 + 𝑟 for some integer 𝑘
◦ Remove these elements and squeeze the sequence

First, consider the following variant:


Maximize the total of 𝑘’s,
assuming we remove all elements
Subproblem
First, consider the following variant:
Maximize the total of 𝑘’s,
assuming we remove all elements
If this variant on all intervals 𝑎𝑝 , … , 𝑎𝑞 are solved,
remaining task is the following 𝑂 𝑛3 -time DP on intervals

𝐷𝑃 𝑝 𝑞 = answer for the original problem


on instance (𝑎𝑝 , … , 𝑎𝑞 )
Subproblem
Given an array 𝑎1 , … 𝑎𝑛 (𝑛 ≤ 500) and integers 𝑑, 𝑟
We can repeat following:
◦ Take interval [𝑝, 𝑞] with 𝑎𝑝 + ⋯ + 𝑎𝑞 = 𝑘𝑑 + 𝑟 for some integer 𝑘
◦ Remove these elements and squeeze the sequence

Assuming we remove all elements,


maximizing the total 𝑘’s is equivalent to
minimizing the number of operations

∑𝑎𝑖 −𝑟⋅#𝑜𝑝𝑒𝑟𝑎𝑡𝑖𝑜𝑛𝑠
Proof: total 𝑘’s =
𝑑
Subproblem
Minimize the number of operations,
assuming we remove all elements

Let 𝑏 be the minimum positive integer with


𝑎1 + ⋯ + 𝑎𝑛 ≡ 𝑏𝑟 (mod 𝑑)

We can show either 𝑏 operation is enough,


or it is impossible to remove entire sequence
Proof: if we use 𝑏 ′ > 𝑏 operations,
we can unify last 𝑏 ′ − 𝑏 + 1 operations into one operation
Subproblem
So the problem is:
Is it possible to remove entire sequence?

This is solved by the following 𝑂 𝑛3 -time DP on intervals


𝐷𝑃 𝑝 𝑞 = maximum number of operations
to remove whole interval (𝑎𝑝 , … , 𝑎𝑞 )

You might also like