#P15351. [COCI 2025/2026 #4] 战斧牛排 / Tomahawk
[COCI 2025/2026 #4] 战斧牛排 / Tomahawk
Problem Description
Consider an matrix . Initially, all elements in are zero.
Use the following conventions: rows are horizontal and columns are vertical. Rows are numbered from top to bottom as , and columns are numbered from left to right as .
There are operations:
- : here, .
- For , add to every cell in column .
- : here, .
- For , add to every cell in column .
- : here, .
- For , add to every cell in row .
After all operations, find the range of the matrix (the difference between the maximum value and the minimum value).
Input Format
The first line contains two positive integers (, ).
The next lines each contain a character and a positive integer , where .
- If , then ;
- otherwise, .
Output Format
Output one integer on a single line, representing the range (the difference between the maximum value and the minimum value).
4 2
L 2
R 1
2
3 3
R 2
D 3
R 2
6
Hint
Sample Explanation
Explanation for sample 1:
$\begin{bmatrix} 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 \end{bmatrix} \rightarrow \begin{bmatrix} 2 & 1 & 0 & 0 \\ 2 & 1 & 0 & 0 \\ 2 & 1 & 0 & 0 \\ 2 & 1 & 0 & 0 \end{bmatrix} \rightarrow \begin{bmatrix} 2 & 1 & 0 & 1 \\ 2 & 1 & 0 & 1 \\ 2 & 1 & 0 & 1 \\ 2 & 1 & 0 & 1 \end{bmatrix}$
Explanation for sample 2:
$\begin{bmatrix} 0 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 0 \end{bmatrix} \rightarrow \begin{bmatrix} 0 & 1 & 2 \\ 0 & 1 & 2 \\ 0 & 1 & 2 \end{bmatrix} \rightarrow \begin{bmatrix} 1 & 2 & 3 \\ 2 & 3 & 4 \\ 3 & 4 & 5 \end{bmatrix} \rightarrow \begin{bmatrix} 1 & 3 & 5 \\ 2 & 4 & 6 \\ 3 & 5 & 7 \end{bmatrix}$
Subtasks
| Subtask ID | Score | Constraints |
|---|---|---|
| is even | ||
| No additional constraints |
Translated by ChatGPT 5