bdoi23
bdoi23
0.1 A. Success
The answer is the number of maxima + 1.
Answer: n + 1
0.2 B. Moo
The sum S can be distributed if and only if S is divisible by the following
expression:
gcd(a1 , a2 , . . . , an )
a1 + a2 + · · · + an
The maximum number not exceeding m that divides this value is given by:
gcd(a1 , a2 , . . . , an )
The maximum integer k ≤ m where k | .
a1 + a2 + · · · + an
0.3 C. Now-or-Never
A person can solve task i followed by task j if the following conditions are met:
ti ≤ tj ,
xi + t i ≤ xj + t j ,
t i − xi ≤ t j − xj .
Optimal Strategy: Sort the tasks lexicographically by the pairs (xi + ti , ti −
xi ). Partition the tasks into the minimum number of non-decreasing subse-
quences (by the second coordinate) using Dilworth’s theorem. The answer is
the length of the longest decreasing subsequence.
Implementation Steps: 1. Use binary search to compute hi (length of the
longest decreasing subsequence starting at i). 2. Group tasks by their h-values
to form minimal subsequences.
Formula:
Answer: max hi
i
0.4 D. World
Optimal Partition: The segments’ endpoints are the farthest pairs of points.
The Manhattan distance between a pair of points (Ai , Bi ) can be expressed as:
X
max m (−1)sj (xj − yj )
s∈{0,1}
j
1
Dynamic Programming Approach: Define dp[i] as the answer for the prefix
of length i. Iterate left-to-right, maintaining the maximum value of dp[i] +
sj j
P
j (−1) ai for each binary sequence s.
Time Complexity:
O(n · 2m )
0.5 E. Hunted
Key Definitions: - Good vertices: Vertices strictly closer to you than to the
police. - Maximum distance d: The distance from the police to any good vertex.
The answer is the maximum distance d of the farthest good vertex w. Police
pursuit reduces d by at least 1 each second.
Algorithms: 1. For non-LCA vertices, use binary lifting to find the highest
good ancestor. 2. Precompute distances from each vertex to the farthest vertex
in its subtree. 3. For the LCA case, use binary lifting to compute max(−hf +ou ),
where hf is the distance from f to the root, and ou is the subtree depth excluding
u.
Time Complexity:
O(n log n)