National Olympiad in Informatics, China, 2014
Recently, little Z has been addicted to a new type of deletion game.
This game takes place on an
Given three parameters
and , where , meaning that is a valid cell on the grid. where , meaning that and are two neighbouring cells on the grid. or , where , meaning that the path does not repeat cells. , where , meaning that the path does not go through any blank cells. , meaning that the path does not start with the number . , meaning that the length of the path has to fall within the given range.
Then, the player will string the digits on the path together into an
integer
The game will provide two parameters
- If
is a prime number, then the prime subscore is , otherwise the prime subscore is . - If
is a palindromic number (i.e. when viewed as a string, is identical whether its letters are arranged forwards or reverse), then the palindromic subscore is , otherwise the palindromic subscore is . - If the prime subscore and the palindromic subscore are both equal to
, then the overall score for the move is . Otherwise, the overall score for the move is equal to the sum of the prime subscore and the palindromic subscore.
If after a move the move's overall score is
- Set
, where . - Examine every cell in the grid. If a cell
satisfies , , and , then set and . Repeat this step until no more cells in the grid satisfy the conditions.
The following is an example of a player making a move and deleting some
cells. In this case,
- The player selects the path containing digits
and , which strung together makes . Since is a prime number, the prime subscore is . Since is not a palindromic number, the palindromic subscore is . Thus, the overall score for the move is . - Since the score of the move is nonzero, the path's values are deleted (as in figure 2).
- Digits above the blank cells drop down (as in figure 3). At this point, the player is ready to make the next move.
We will also give you a parameter
where
Little Z finds himself hooked to this game, unable to step away. She would like your help. For the given parameters, provide a series of moves to play the game. Of course, the final score should be as high as possible.
Input Specification
There will be 10 files game1.in
~ game10.in
that will be given to
your program (through standard input). They can be downloaded here for
you to study:
game.zip.
For each test case:
The first line of input will contain an integer from gamei.in
will have
The second line of input will contain eight space-separated integers
The next
The input will not contain any extra or trailing spaces.
Output Specification
The first line of output should contain a single integer
The output should not contain extra spaces or lines. Adjacent values on
the same line should be separated by a single space.
Your output should not exceed 1MB in size. The data guarantees that a
valid answer will not exceed this upper bound.
Sample Input 1
0
3 3 100 2 3 1 1 0
2 1 1
2 3 3
4 7 1
Sample Output 1
4
2 2 2 3 2
2 3 1 3 2
2 2 1 3 1
3 1 3 2 3 3 3
Explanation 1
Four deletions are made. The deleted paths and move scores are,
respectively:
Sample Input 2
0
1 3 100 2 3 1 1 1
2 1 1
Sample Output 2
1
2 1 2 1 3
Explanation 2
Only one deletion is made. The deleted path is
Grading
For each test case, we have set up 9 parameters
Score | Condition |
---|---|
10 | |
9 | |
8 | |
7 | |
6 | |
5 | |
4 | |
3 | |
2 | |
1 |
Experimentation
We provide a tool check
(GNU/Linux:
check,
Windows:
check.exe)
for you to help check if your output program is valid.
The usage for this program (on Linux) is
./check <case_no>
where <case_no>
is the number of the test case.
On Windows, use .\
instead of ./
.
The checker should be placed in the same directory as your input and output files.
For example, ./check 3
should be executed in a directory containing files game3.in
and game3.out
to test whether the output would be accepted.
After you invoke this program, the checker will provide the result to the execution of your output file in one of the following ways:
Abnormal termination
: An unknown error occurred.Input/Output file does not exist.
: We cannot load your input or output file.Output invalid!
: There is an error with your output file. A general error message may now be included.Details: xxx.
: Other information.Correct! Your answer is x.
: Your output is acceptable. Your final score is .
Note that the checker is not guaranteed to work for inputs other than the ones provided.
Problem translated to English by .
Comments