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
D - Trophy
Problem Statement
A game consists of $N$ stages. The $i$-th stage is represented by a pair $(A_i, B_i)$.
To clear a stage, you must first spend $A_i$ time watching an introduction. Then, it takes $B_i$ time to clear the stage. For subsequent clears of the same stage, the introduction is skipped (i.e., clearing the $i$-th stage $M$ times in total requires $A_i + M \times B_i$ time).
Initially, only the first stage is unlocked. After clearing any stage, the next stage is automatically unlocked (except the last stage). Find the minimum time required to clear exactly $X$ stages (repeats count).
$1\le N\le 2\times 10^5$
$1\le A_i,B_i\le 10^9$
$1\le X\le N$
Input Format
$N~X$
$A_1~B_1$
$\vdots$
$A_N~B_N$
Output Format
Print the answer.
Sample
Refer to AtCoder.
Analysis
The optimal strategy involves clearing some initial stages once, then repeatedly clearing a particular stage. Using prefix sums and enumerating each stage, we achieve $\mathcal O(n)$ time complexity.
Code
|
|
E - Packing Potatoes
Problem Statement
There are $10^{100}$ potatoes arranged in a sequence. The weight of the $i$-th potato is $W_{i \bmod N}$ (weights cycle every $N$ elements).
Takahashi packs potatoes into boxes sequentially. When the total weight in a box reaches at least $X$, he starts a new box.
Given $Q$ queries, each asking for the number of potatoes in the $K_i$-th box.
$1\le N,Q\le 2\times 10^5$
$1\le X,W_i\le 10^9$
$1\le K_i\le 10^{12}$
Input Format
$N~Q~X$
$W_0~\dots~W_{N-1}$
$K_1$
$\vdots$
$K_Q$
Output Format
Print $Q$ lines, each containing the answer.
Sample
Refer to AtCoder.
Analysis
Cyclic pattern problem.
Code
|
|
F - Main Street
WJ...
G - Triangle
Problem Statement
Given a simple undirected graph $G$ with $N$ vertices and its adjacency matrix $A$:
- $A_{i,j}=1$ indicates an edge between vertices $i$ and $j$
- $A_{i,j}=0$ otherwise (with $A_{i,i}=0$ for all $i$)
Count the number of triples $(i,j,k)$ satisfying:
- $1\le i < j < k \le N$
- $A_{i,j}=A_{i,k}=A_{j,k}=1$
$3\le N\le 3000$
Input Format
$N$
$A_{1,1}A_{1,2}\dots A_{1,N}$
$A_{2,1}A_{2,2}\dots A_{2,N}$
$\vdots$
$A_{N,1}A_{N,2}\dots A_{N,N}$ (e.g., 10110
)
Output Format
Print the count.
Sample
Refer to AtCoder.
Analysis
The naive $\mathcal O(N^3)$ approach can be optimized using bitset operations. For each edge $(i,j)$, compute the intersection of $i$’s and $j$’s adjacency lists, then sum all intersections and divide by 3. Time complexity: $\mathcal O(N^3 / w)$ where $w$ is bitset width (64).
Code
|
|