| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 2048 MB | 0 | 0 | 0 | 0.000% |
You are given a board of size $n \times m$, with the top left corner at $(1, 1)$ and the bottom right corner at $(n, m)$. There are $k$ different colors of pieces, numbered from $1$ to $k$. Initially, each cell contains one piece.
There are $q$ operations in total. Each operation involves swapping two adjacent (up, down, left, right) pieces. After this, every continuous sequence of at least $3$ pieces of the same color in the same row or column will be eliminated.
After elimination, all pieces will fall down due to gravity, creating empty spaces at the top of the column. Once all pieces have fallen, if there are still pieces that can be eliminated, a chain reaction will occur, continuing to eliminate until no more eliminations are possible. A single elimination followed by a fall is called "one round of elimination", and we can define the "number of rounds" of elimination triggered by one operation.
Some pieces have special properties that trigger special effects when eliminated. There are a total of $6$ types of special properties:
Triggering a piece's special effect may also trigger other pieces' special effects, but these are all triggered within the same round of elimination, as a chain reaction, before falling due to gravity.
In the game, each operation must be valid, meaning the two positions involved in the operation must be adjacent and not empty, and the operation must lead to a piece elimination. If an operation is not valid, it is skipped. The game ends after all $q$ operations are completed.
The main color of a valid operation is defined as the color that is directly eliminated by the swap (not including those triggered by special effects or falling). It is easy to see that a valid operation has $1$ or $2$ main colors.
In the game, players aim to score as many points as possible through their operations. The scoring rules consist of $5$ types: elimination score + chain score + combination score + pattern score + endgame score.
\begin{itemize}
Given the initial state of a game and each operation performed by the player, you need to calculate the player's total score.
The first line of input contains four integers: $n$, $m$, $k$, and $q$ ($2 \leq n, m \leq 50$; $m + n > 4$; $2 \leq k \leq 100$; $1 \leq q \leq 1000$).
The next $n$ lines, each containing $m$ integers $a_{i,j}$, represent the initial state of the pieces' colors from top to bottom and from left to right ($1 \le a_{i,j} \leq k$).
The following $n$ lines, each containing $m$ integers $b_{i,j}$, represent the initial state of the pieces' special effects, as described in the problem statement. Specifically, $b_{i,j} = 0$ indicates no special effect ($0 \le b_{i,j} \leq 6$).
Each of the next $q$ lines contains four positive integers: $x_{i,1}$, $y_{i,1}$, $x_{i,2}$, and $y_{i,2}$. They indicate the swap of pieces at coordinates $(x_{i,1}, y_{i,1})$ and $(x_{i,2}, y_{i,2})$ ($1 \leq x_{i,1}, x_{i,2} \leq n$; $1 \le y_{i,1}, y_{i,2} \leq m$).
It is guaranteed that the initial state has no direct elimination situations.
Output a single line with an integer representing the total score at the end of the game.
8 8 5 5 1 1 5 1 5 4 5 3 2 1 2 2 5 4 3 2 1 4 1 4 2 1 5 4 2 1 5 5 2 1 4 4 2 3 5 2 3 4 2 2 4 2 4 3 3 2 4 5 1 3 4 3 5 2 4 3 3 4 2 5 2 1 1 2 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 0 0 3 1 0 0 0 0 3 0 0 0 0 0 0 0 0 0 1 4 3 2 4 2 5 4 5 5 7 2 7 3 8 5 8 6 6 7 6 8
11692
8 8 5 8 1 1 5 1 5 4 5 3 2 1 2 2 5 4 3 2 1 4 1 4 2 1 5 4 2 1 5 5 2 1 4 4 2 3 5 2 3 4 2 2 4 2 4 3 3 2 4 5 1 3 4 3 5 2 4 3 3 4 2 5 2 1 1 2 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 0 0 3 1 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 1 1 2 2 3 2 4 2 3 2 3 3 4 2 4 3 5 4 5 5 7 2 7 3 8 5 8 6 6 7 6 8
684
5 5 2 1 1 1 2 1 1 1 1 2 1 1 2 2 1 2 2 1 1 2 1 1 1 1 2 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 3 4 3
3023
The sums of the first three types of scores after each operation are: $315$, $417$, $429$, $435$, $482$. After the $5$-th operation, the pattern score is calculated, with the optimal pattern being $(1\ 2\ 4\ 2\ 4)$, yielding a score of $200 + 4 \cdot 2 + 2 \cdot 1 = 210$. At the end of the game, we obtain both types of endgame bonuses, resulting in the total score of $11\,692$.