#P5267. [NOI2014] 消除游戏
[NOI2014] 消除游戏
Problem Description
Recently, Little Z became addicted to a new elimination game. The game is played on an grid. Initially, each cell contains an integer from . After eliminations, blank cells may appear in the grid, denoted by . For convenience, denote the number in row , column as , and its coordinate as .
Given three parameters , and , the player can perform at most operations. In each operation, the player needs to find a path of length in the grid. Formally, the path is represented by two sequences of length , and , satisfying:
- for , i.e., is a valid position in the grid.
- $\left|x_i-x_{i+1} \right|+ \left|y_i-y_{i+1} \right|=1$ for , i.e., and are adjacent cells in the grid.
- or for , i.e., the path cannot pass through any cell more than once.
- for , i.e., the path cannot pass through blank cells.
- , i.e., the path cannot start with the digit .
- , i.e., the path length must be within the given range.
Concatenate the digits along the path into an integer , formally:
The game provides two parameters to compute the score for this operation:
- If is a prime number, you get the prime score ; otherwise, the prime score is .
- If is a palindrome (i.e., viewing the decimal representation of as a string, its reverse is exactly the same as itself), you get the palindrome score ; otherwise, the palindrome score is .
- If both the prime score and the palindrome score are , then the score of this operation is . Otherwise, the score of this operation is the sum of the prime score and the palindrome score.
After each operation, if the score of this operation equals , then you waste one operation and the grid does not change. If the score of this operation is greater than , then the numbers on the path are replaced with blanks, and the numbers above blanks fall vertically. Formally, perform the following steps:
- Set for .
- Enumerate all cells. If there exists a cell such that , , and , then perform . Repeat this operation until no such cell exists in the grid.
We also provide a parameter . After all operations are completed, the player’s final score is determined by : if , then the final score is the sum of the scores of all operations ; if , then the final score is the sum of the scores of all operations divided by and floored, i.e.,
$$S = \begin{cases} m, & F=0\\\\ \left \lfloor \frac{m}{2^d} \right \rfloor, & F=1 \end{cases}$$where is the number of non-blank cells in the final grid.
Little Z is so obsessed with this interesting game that she cannot stop. She wants to ask you for help: for the given input parameters, provide an operation plan for the game state. Of course, the higher the final score, the better.
Input Format
This is an output-only problem.
For each input file, line contains space-separated integers , with the same meanings as in the statement.
Then follow lines, each containing integers, describing the grid . Numbers are separated by one space.
The input file will not contain extra blank lines, and there will be no extra spaces at the end of lines.
Output Format
For the given input files game1.in ~ game10.in, you need to submit your output files game1.out ~ game10.out respectively.
The first line of the output file is an integer , the number of operations you perform.
Then the output file should contain lines, each describing one operation. For each line, the first integer indicates the length of the chosen path for this operation. Then follow numbers: .
The output file should not contain extra spaces or blank lines. Multiple integers on the same line should be separated by one space.
3 3 100 2 3 1 1 0
2 1 1
2 3 3
4 7 1
4
2 2 2 3 2
2 3 1 3 2
2 2 1 3 1
3 1 3 2 3 3 3
1 3 100 2 3 1 1 1
2 1 1
1
2 1 2 1 3
Hint
Sample Explanation 1
The numbers eliminated in the eliminations and their corresponding scores are: , score ; , score ; , score ; , score . The total score is . There may be a better plan.
Sample Explanation 2
This plan contains only one elimination operation. The eliminated number is , and the score for this operation is . Since , the final score is the sum of operation scores divided by and floored, which is . If you choose the elimination path , you will get the best possible score for this game state, which is .
Scoring
For each test, we set scoring parameters . If your output is invalid, you get points. Otherwise, if the game score in your solution is , your score will be given by the table below:
::cute-table{tuack=2}
| Score | Condition | Score | Condition |
|---|---|---|---|
Additional Files
The checker must be compiled and used by yourself.
Please go to Github to download the latest source code of testlib.h.
Translated by ChatGPT 5