2020icpc Macau Analyze
2020icpc Macau Analyze
Contest Editorial
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
A. Accelerator
Task
We are given n accelerators a1 , a2 , . . . , an . The final velocity is
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
A. Accelerator
Observation
((. . . ((a1 + 1) a2 + 1) · · · + 1) an−1 + 1) an
= a1 a2 a3 . . . an + a2 a3 . . . an + · · · + an−1 an + an
Task
We are given n strings T1 , T2 , . . . , Tn of length m and a string R.
For each i (1 ≤ i ≤ |R|), we are required to compute the expected
length of the final string when it contains any string in T as
substring if we repeat appending the i-th (1 ≤ i ≤ k) lowercase
letter with with probability pi to the end of the current string, here
the initial string is R[1..i].
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
B. Boring Problem
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
B. Boring Problem
Idea
Assume x has t (t ≥ 1) children g(x, c1 ), g(x, c2 ), . . . , g(x, ct ) in T′ ,
we can know E(g(x, c1 )) if we know E(x) and all other values of
E(g(x, j)) according to
∑
E(x) − 1 − j,j̸=c1 E(g(x, j))pj
E(g(x, c1 )) =
pc1
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
B. Boring Problem
Observation
If we treat E(g(x, c2 )), E(g(x, c3 )), . . . , E(g(x, ct )) as unknown
variables, we can know E(g(x, c1 )) because
dep(g(x, j)) ≤ dep(x) < dep(g(x, c1 )), all other vertices are
considered before.
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
C. Club Assignment
Task
We are given n positive integers w1 , w2 , . . . , wn , divide them into
two groups such that
min {wi ⊕ wj }
1≤i<j≤n, i and j are in the same group
is maximized.
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
C. Club Assignment
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
C. Club Assignment
Lemma
Find the minimum spanning tree of G, assign adjacent vertices into
different groups is optimal.
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
D. Artifacts
Task
We are given 5 artifacts, and we are asked to calculate the
expected damage.
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
D. Artifacts
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
E. Mountain
Task
There is a mountain
At each point (i, hi ), a picture is taken, which covers all the points
(x, y) where i − W ≤ x ≤ i + W and hi − H ≤ y ≤ hi + H.
For k = 1, 2, . . . , n, keep exactly k pictures, maximize the total
area of the mountain which is covered by at least one picture.
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
E. Mountain
Observation
The picture taken at (i, hi ) can only coincide with those pictures
taken at (j, hj ) where |i − j| ≤ 2W − 1.
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
F. Fixing Networks
Task
Construct a simple undirected graph with n vertices and c
components, where the degree of each vertex is d.
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
F. Fixing Networks
d = 0 or d = 1 are trivial.
The cases for no solution:
c(d + 1) > n: Number of vertices is not enough.
Both n and d are odd: The sum of degrees is not even.
When there is a solution, we can construct c − 1 components
by assign each as a complete graph with d + 1 vertices.
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
F. Fixing Networks
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
G. Game on Sequence
Task
There is a sequence A1 , A2 , . . . , An with non-negative integers.
Initially a token is at position k. Two players take turns moving the
token from i to a position j on the right side such that Aj differs
from Ai on at most one bit in binary representation.
We are required to perform two types of operations:
Append an integer at the end of the sequence A.
Predict the winner when the token is at position k.
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
G. Game on Sequence
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
G. Game on Sequence
Lemma
For two positions i and j, where i < j and Ai = Aj , fi = True
always holds.
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
H. Fly Me To The Moon
Task
There is an infinity grid and n types of spacecrafts d1 , d2 , . . . , dn .
Assume we are at (x, y), we can choose a type of spacecraft di and
fly to (x + dx, y + dy) (dx, dy ≥ 0) where 0 < dx2 + dy2 ≤ d2i .
There are m broken points we can’t touch. We are required to
count the number of ways to reach (1000, 1000) from (0, 0).
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
H. Fly Me To The Moon
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
H. Fly Me To The Moon
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
I. Nim Cheater
Task
There is a sequence of piles of stones, Bob can pay to remove
some piles from the game.
Initially the sequence is empty. We are required to perform three
types of operations:
Append a new pile at the end of the sequence.
Delete the rightmost pile.
Find the cheapest way for Bob to cheat such that the first
player of the Nim game will lose.
The memory limit is 8MB.
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
I. Nim Cheater
The first player will lose iff the XOR sum of all numbers is
zero.
We need to find a subset of numbers such that the XOR sum
is zero and the total cost is maximized, and remove the left
part to cheat.
Observation
The modifications form a rooted tree.
Construct the rooted tree, we need to find the answer for each
vertex.
Let’s denote dp[i][j] as the maximum total cost such that the
XOR of chosen numbers is j if we choose numbers among the
path from the root to the i-th vertex.
Time & space complexity: O(na), which is unfortunately
unable to fit in the 8MB limit.
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
I. Nim Cheater
Idea
Try different DFS orders won’t affect the answer.
Lemma
There will be at most O(log n) light edges on a path, so the space
complexity is O(a log n).
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
J. Jewel Grab
Task
Given a sequence of jewels, each jewel has its color and its value.
We are required to perform two types of operations:
Modify a jewel in the sequence.
Find the maximum total value of taken jewels if we start at
position s and move right, skipping at most k jewels, such
that no two taken jewels share the same color.
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
J. Jewel Grab
For the i-th jewel, find the first jewel prei with the same color
on the left side of it.
For each query, let’s move right from s step by step, assume
we are at j with color cj and value vj :
If prej < s, it is the first time we meet a jewel in such color,
take it.
Otherwise prej ≥ s, we should compare it with the previous
one, greedy keep the one with larger value, and skip one of
them.
The second part takes place at most k times, which is
acceptable for k ≤ 10.
To speed up the first part, we need to find the next position j
such that prej ≥ s, and find the sum in this range, which can
be done by traveling on the segment tree in O(log n).
Time complexity: O(k log n) per query.
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
K. Candy Ads
Task
Given n advertisement posters, we are required to choose some of
them such that no two chosen advertisement posters will occupy
the same pixel at the same time.
We are also given m extra conditions, each of which requires us to
keep at least one of two listed advertisement posters.
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
K. Candy Ads
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
K. Candy Ads
Idea
Use Bitset to find the adjacent vertices and skip visited vertices.
2
Time complexity: O( nw + m).
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
L. Random Permutation
Task
An integer sequence a1 , a2 , · · · , an is generated randomly, and the
probability of being 1, 2, · · · , n are all n1 for each ai .
We are required to calculate the expected number of permutations
p1 , p2 , · · · , pn from 1 to n such that pi ≤ ai holds for each
i = 1, 2, · · · , n.
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
L. Random Permutation
Observation
No matter what the permutation p is, the number of the
corresponding sequence a is always n!.
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial
Thank you!
Prepared by Zhejiang University The 2020 ICPC Asia Macau Regional Contest Editorial