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 - Chinchirorin
Problem Statement
Given three integers $a,b,c$, if two of them are equal, output the third one; otherwise, output $0$.
$1\le a,b,c\le 6$
Input Format
$a~b~c$
Output Format
Output the third value if two of $a,b,c$ are equal; otherwise, output $0$.
Samples
$a$ | $b$ | $c$ | Output |
---|---|---|---|
$2$ | $5$ | $2$ | $5$ |
$4$ | $5$ | $6$ | $0$ |
$1$ | $1$ | $1$ | $1$ |
Analysis
Problem A remains straightforward. Directly check the three possible equality cases.
Code
|
|
B - AtCoder Condominium
Problem Statement
Given $N$ and $K$, compute $\sum\limits_{i=1}^N\sum\limits_{j=1}^K \overline{i0j}$.
$1\le N,K\le 9$
Input Format
$N~K$
Output Format
Output $\sum\limits_{i=1}^N\sum\limits_{j=1}^K \overline{i0j}$.
Samples
$N$ | $K$ | Output |
---|---|---|
$1$ | $2$ | $203$ |
$3$ | $3$ | $1818$ |
Analysis
Brute-force works, but here’s an $\mathcal O(1)$ approach:
Since $\overline{i0j}=100i+j$ and $1+2+\dots+N=\frac{N(N+1)}2$, we derive:
- $\sum\limits_{i=1}^N\sum\limits_{j=1}^K \overline{i0j}=\frac{100N(N+1)K+K(K+1)N}2$
Code
|
|
C - Friends and Travel costs
Problem Statement
There are $10^{100}+1$ villages numbered $0,1,\dots,10^{100}$. Moving between adjacent villages costs $1$ yen.
Taro starts at village $0$ with $K$ yen and wants to reach the highest possible village.
He has $N$ friends. The $i$-th friend gives $B_i$ yen when Taro reaches village $A_i$.
Find the highest village Taro can reach.
$1\le N\le 2\times10^5$
$1\le K\le 10^9$
$1\le A_i\le 10^{18}$
$1\le B_i\le 10^9$
Input Format
$N~K$
$A_1~B_1$
$A_2~B_2$
$\dots$
$A_N~B_N$
Output
Output the highest village number Taro can reach.
Samples
Sample Input 1
|
|
Sample Output 1
|
|
Sample Input 2
|
|
Sample Output 2
|
|
Use 64-bit integers.
Sample Input 3
|
|
Sample Output 3
|
|
A village may contain multiple friends.
Analysis
Sort friends by $A_i$. Process intervals between friends, checking if Taro can reach each $A_i$ with remaining funds.
Code
Note: Sorting uses a priority queue.
|
|
D - Pond
Problem Statement
Given an $N\times N$ matrix $A$, find the minimum median among all $K\times K$ submatrices. The median is the $(\left\lfloor\frac{K^2}2\right\rfloor+1)$-th largest value.
$1\le K\le N\le 800$
$1\le A_{i,j}\le 10^9$
Example illustration:
Input Format
$N~K$
$A_{1,1}~A_{1,2}~\dots~A_{1,N}$
$\vdots$
$A_{N,1}~A_{N,2}~\dots~A_{N,N}$
Output Format
Output the answer.
Samples
Sample Input 1
|
|
Sample Output 1
|
|
Sample Input 2
|
|
Sample Output 2
|
|
Analysis
Binary search the answer. For each candidate value, use matrix prefix sums to count elements exceeding it in each submatrix. Time complexity $\mathcal O(n^2\log\max\{A\})$.
Code
|
|
E - White Pawn
Problem Statement
On a $(2N+1)\times(2N+1)$ chessboard, a white pawn starts at $(0,N)$. $M$ black squares exist at $(X_i,Y_i)$. The pawn moves:
- Down to white $(i+1,j)$,
- Diagonally down-left to black $(i+1,j-1)$,
- Diagonally down-right to black $(i+1,j+1)$.
Find how many columns in the last row are reachable.
$1\le N\le 10^9$
$0\le M\le 2\times 10^5$
Input Format
$N~M$
$X_1~Y_1$
$\vdots$
$X_M~Y_M$
Output Format
Output the count.
Samples
Sample Input 1
|
|
Sample Output 1
|
|
Sample Input 2
|
|
Sample Output 2
|
|
Analysis
Process black squares row-wise. Maintain reachable columns using a set. For each black row, update reachable positions based on adjacent cells.
Code
|
|