Translation Notice
This article was machine-translated using DeepSeek-R1.
- Original Version: Authored in Chinese by myself
- Accuracy Advisory: Potential discrepancies may exist between translations
- Precedence: The Chinese text shall prevail in case of ambiguity
- Feedback: Technical suggestions regarding translation quality are welcomed
A - Good morning
Problem Summary
On the same day, Takahashi wakes up at $A$ hours $B$ minutes, and Aoki wakes up at $C$ hours $D$ minutes 1 second. Who wakes up earlier?
$0\le A,C < 24$
$0\le B,D < 60$
Input Format
$A~B~C~D$
Output Format
Output the name of the earlier riser (Takahashi
or Aoki
).
Samples
$A$ | $B$ | $C$ | $D$ | Output |
---|---|---|---|---|
$7$ | $0$ | $6$ | $30$ | Aoki |
$7$ | $30$ | $7$ | $30$ | Takahashi |
$0$ | $0$ | $23$ | $59$ | Takahashi |
Analysis
The approach is straightforward: directly check whether $(A,B)\le(C,D)$ holds.
Code
|
|
B - Mex
Problem Summary
Given an integer sequence $A=(A_1,\dots,A_N)$, find the smallest natural number not present in $A$.
$1\le N\le 2000$
$0\le A_i\le 2000$
Input Format
$N$
$A_1~\dots~A_N$
Output Format
Output the smallest natural number not in $A$.
Samples
Samples omitted; please visit AtCoder.
Analysis
Since $0\le A_i\le 2000$, we can use an array to track occurrences of numbers in $[0,2001]$.
There are multiple approaches for this problem; here we present the fastest algorithm with $\mathcal O(N)$ time complexity.
Code
|
|
C - Choose Elements
Problem Summary
Given two integer sequences $A=(A_1,\dots,A_N)$ and $B=(B_1,\dots,B_N)$, determine if there exists a sequence $X=(X_1,\dots,X_N)$ satisfying:
- $X_i=A_i$ or $X_i=B_i$
- $|X_i-X_{i+1}|\le K$ for all $1\le i < N$
$1\le N\le 2\times 10^5$
$1\le K\le 10^9$
$1\le A_i,B_i\le 10^9$
Input Format
$N~K$
$A_1~\dots~A_N$
$B_1~\dots~B_N$
Output Format
Output Yes
if such $X$ exists; otherwise, output No
.
Samples
Samples omitted; please visit AtCoder.
Analysis
This problem can be solved using dynamic programming.
Let $f(i)$ denote whether $X_i$ can be $A_i$, and $g(i)$ denote whether $X_i$ can be $B_i$.
State transitions are straightforward; see code for details.
Code
|
|
Note: There’s a peculiar alternative solution that checks if at least one of the four adjacent connections exists, such as in #30453703. If anyone can prove its correctness, please comment below!
D - Polynomial division
Problem Summary
$$ A(x)=\sum_{i=0}^N A_iX^i\\ B(x)=\sum_{i=0}^M B_iX^i\\ C(x)=\sum_{i=0}^{N+M} C_iX^i $$
where $A$ and $C$ coefficients are known and $A(x)\times B(x)=C(x)$, find coefficients $B_0,\dots,B_M$.
$1\le N,M < 100$
$|A_i|\le 100$
$|C_i|\le 10^6$
$A_N\ne0$, $C_{N+M}\ne0$
A valid $B$ is guaranteed.
Input Format
$N~M$
$A_0~\dots~A_N$
$C_0~\dots~C_{N+M}$
Output Format
Output $B_0,\dots~B_M$ separated by spaces.
Samples
Samples omitted; please visit AtCoder.
Analysis
Simulate the polynomial long division process by tracking coefficients.
Reference: Polynomial long division
Code
|
|
E - Wrapping Chocolate
Problem Summary
We have $N$ chocolates and $M$ boxes. The $i$-th chocolate has dimensions $A_i\times B_i$, and the $j$-th box has dimensions $C_j\times D_j$. Determine if all chocolates can be packed into boxes such that:
- Each box contains exactly one chocolate.
- For chocolate $i$ in box $j$, $A_i\le C_j$ and $B_i\le D_j$ must hold.
$1\le N\le M\le 2\times10^5$
$1\le A_i,B_i,C_i,D_i\le 10^9$
Input Format
$N~M$
$A_1~\dots~A_N$
$B_1~\dots~B_N$
$C_1~\dots~C_M$
$D_1~\dots~D_M$
Output Format
Output Yes
if possible; otherwise, No
.
Analysis
Greedy algorithm steps:
- Sort all items (chocolates and boxes) in descending order of length. When lengths are equal, boxes come first.
- Use a multiset to track available box heights. For each chocolate, remove the smallest box height ≥ its height.
Time complexity: $\mathcal O((N+M)\log(N+M))$
Code
|
|