|시간 제한||메모리 제한||제출||정답||맞힌 사람||정답 비율|
|120 초 (추가 시간 없음)||1024 MB||55||3||2||40.000%|
Mr. Raven is stuck in a cave represented by a matrix of N rows and M columns, where rows are numbered from 1 to N from top to bottom, and columns are numbered from 1 to M from left to right. The cell at the i-th row and the j-th column is denoted by (i, j). Mr. Raven is currently at the cell (SR, SC), and the exit of the cave is located at the cell (TR, TC).
Some cells of the cave may contain obstacles. Mr. Raven cannot step into a cell that has an obstacle. Other cells may contain traps. The first time that Mr. Raven enters a cell with a trap, he must spend a number of energy points equal to the strength of the trap. If he has fewer energy points than needed, he cannot enter the cell. Moreover, some other cells may contain potions. The first time that Mr. Raven enters a cell with a potion, he gains energy points equal to the strength of the potion.
Mr. Raven initially has E energy points. He can move between cells that share an edge (not just a corner). On the exit cell, Mr. Raven can choose not to exit the cave and continue to explore the cave if he wants to. Can you help him find the maximum number of energy points he can have when he exits the cave, if it is possible to do so?
The first line of the input gives the number of test cases, T. T test cases follow. Each test case consists of one line with seven integers N, M, E, SR, SC, TR and TC as described above. The i-th of the next N lines describes the i-th row of the cave. Each line consists of M integers Vij; the j-th of these represents the cell in the j-th column of the i-th row. Each Vij can be one of the following
For each test case, output one line containing
Case #x: y, where
x is the test case number (starting from 1) and
y is the maximum energy points that Mr. Raven can have when he reaches the exit of the cave. If it is not possible for Mr. Raven to reach the exit, output
2 4 4 100 1 1 4 4 0 0 0 0 0 0 0 0 0 0 0 -100000 0 0 -100000 0 8 8 250 7 1 1 7 -100000 -100000 -100000 -100000 -100000 -100000 0 -100000 -100000 0 -100000 0 -400 0 0 -100000 -100000 100 -300 0 -100000 -300 -100000 -100000 -100000 0 -100000 500 -100000 250 0 -100000 -100000 -200 -100000 -100000 -100000 -100000 -100 -100000 -100000 0 -100000 0 0 50 50 -100000 0 0 -100 0 -100000 50 -100000 -100000 -100000 -100000 -100000 -100000 -100000 -100000 -100000 -100000
Case #1: -1 Case #2: 250
In Sample Case #1, it is not possible for Mr. Raven to reach the exit.
In Sample Case #2, the cave is as depicted in the following image where
In this case, one of the optimal ways to reach the exit with maximum energy points is to
Note that this case will not appear in the Small dataset.
Contest > Google > Kick Start > Google Kick Start 2018 > Round G C번