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 - Payment
Problem Statement
If paying with a ¥1000 banknote (assuming available), how much change will the clerk return when paying for an item costing ¥N?
$1\le N\le 10000$
Input Format
$N$
Output Format
Single line with the change amount.
Samples
Input | Output |
---|---|
1900 | 100 |
3000 | 0 |
Analysis
Special cases:
- If $N$ is divisible by 1000, output 0.
- Otherwise, output $1000 - (n\mod1000)$.
Code
|
|
B - Judge Status Summary
Problem Statement
A user solved a programming problem, receiving test results in four statuses: AC
, WA
, TLE
, RE
. Given $N$ test cases with results $S_1, S_2, \dots, S_N$, count and output the occurrences of each status.
$1\le N\le 10^5$
Each $S_i$ is AC
, WA
, TLE
, or RE
.
Input Format
$N$
$S_1$
$S_2$
$:$
$S_N$
Output Format
|
|
Note: Use lowercase ‘x’ instead of ‘×’!
Samples
Sample Input 1
|
|
Sample Output 1
|
|
Counts: 3, 1, 2, 0 respectively.
Sample Input 2
|
|
Sample Output 2
|
|
All test cases passed.
Analysis
Though other methods exist, we use map
for simplicity (may be overkill).
Code
|
|
C - H and V
Problem Statement
Given a grid with $H$ rows and $W$ columns. Cell $(i,j)$ ($1\le i\le H$, $1\le j\le W$) is either #
(black) or .
(white). Select any rows and columns to paint red. How many selection methods leave exactly $K$ black cells?
$1\le H, W\le 6$
$1\le K\le HW$
Input Format
$H~W~K$
$c_{1,1}~c_{1,2}~\dots~c_{1,W}$
$c_{2,1}~c_{2,2}~\dots~c_{2,W}$
$\vdots$
$c_{H,1}~c_{H,2}~\dots~c_{H,W}$
Output Format
Single line with the valid method count.
Samples
Sample Input 1
|
|
Sample Output 1
|
|
Five methods involving row 1 and/or columns 1-3.
Sample Input 2
|
|
Sample Output 2
|
|
Only possible by selecting nothing.
Sample Input 3
|
|
Sample Output 3
|
|
Impossible.
Sample Input 4
|
|
Blogger’s note: This is the largest test case. Local runtime check ensures no TLE.
Sample Output 4
|
|
Analysis
Brute-force enumeration using bitmasking. Paint selected rows/columns to white (.
), then count remaining black cells.
Code
|
|
D - Chat in a Circle
Problem Statement
$N$ people arrive sequentially to form a circle. Each person’s comfort equals the smaller friendliness value of their immediate neighbors (first person gets 0). Maximize total comfort.
$2\le N\le 2\times10^5$
$1\le A_i\le 10^9$
Input Format
$N$
$A_1~A_2~\dots~A_N$
Output Format
Single line with maximum total comfort.
Samples
Sample Input 1
|
|
Sample Output 1
|
|
Comfort sum: 0+3+2+2=7.
Sample Input 2
|
|
Sample Output 2
|
|
Analysis
Greedy approach: Sort descending, insert each person into position yielding maximum current comfort. Use priority queue.
Code
|
|