Problem Statement
Halloween season has arrived. As a test of courage, you are about to challenge a haunted house.
There is a haunted house with $F$ floors, and each floor is represented by an $H$-row by $W$-column grid. Let cell $(k,i,j)$ be the cell at the $i$-th row from the top and $j$-th column from the left of the grid representing floor $k$.
The content of cell $(k,i,j)$ is represented by the character $S_{k,i,j}$ as follows:
- If
$S_{k,i,j}$is a digit (0-9), cell$(k,i,j)$is an empty cell with a number of coins equal to the single-digit integer represented by the digit. - If
$S_{k,i,j}$is#, cell$(k,i,j)$is a wall cell.
You can move directly from an empty cell $(k,i,j)$ to another cell $(k', i', j')$ if cell $(k', i', j')$ is an empty cell and one of the following is satisfied:
$k' = k$and$|i' - i| + |j' - j| = 1$are satisfied.$(k', i', j') = (k+1, i, j)$is satisfied.$(k', i', j') = (k-1, i, j)$is satisfied, and a ladder is placed at cell$(k,i,j)$.
You cannot move outside the grid.
You are given $Q$ questions; answer each of them. The $i$-th question ($1 \leq i \leq Q$) is as follows:
- Find the maximum total number of coins in the cells you visit if you choose exactly one empty cell and place a ladder there, start at cell
$(G_i, A_i, B_i)$, and repeatedly move.
Each question is independent. That is, a ladder placed for one question does not affect other questions.
Constraints
$F,H,W$are integers.$1 \leq F \leq 10$$1 \leq H,W \leq 500$$S_{k,i,j}$is either a digit (0,1,2,3,4,5,6,7,8,9) or#. ($1 \leq k \leq F, 1 \leq i \leq H, 1 \leq j \leq W$)$Q$is an integer.$1 \leq Q \leq 10^5$$G_i, A_i, B_i$are integers. ($1 \leq i \leq Q$)$1 \leq G_i \leq F$($1 \leq i \leq Q$)$1 \leq A_i \leq H$($1 \leq i \leq Q$)$1 \leq B_i \leq W$($1 \leq i \leq Q$)$S_{G_i, A_i, B_i}$is not#. ($1 \leq i \leq Q$)
Input
The input is given from Standard Input in the following format:
F H W
S_{1,1,1} S_{1,1,2} \cdots S_{1,1,W}
S_{1,2,1} S_{1,2,2} \cdots S_{1,2,W}
\vdots
S_{1,H,1} S_{1,H,2} \cdots S_{1,H,W}
S_{2,1,1} S_{2,1,2} \cdots S_{2,1,W}
S_{2,2,1} S_{2,2,2} \cdots S_{2,2,W}
\vdots
S_{2,H,1} S_{2,H,2} \cdots S_{2,H,W}
\vdots
S_{F,1,1} S_{F,1,2} \cdots S_{F,1,W}
S_{F,2,1} S_{F,2,2} \cdots S_{F,2,W}
\vdots
S_{F,H,1} S_{F,H,2} \cdots S_{F,H,W}
Q
G_1 A_1 B_1
G_2 A_2 B_2
\vdots
G_Q A_Q B_Q
Output
Output $Q$ lines. The $i$-th line ($1 \leq i \leq Q$) should contain the answer to the $i$-th question.
样例
3 5 6
######
##5###
#1#11#
#1#11#
######
######
##313#
#4##1#
#242##
######
######
#0####
##4###
###99#
######
3
1 2 3
2 3 2
3 2 2
47
34
0
3 6 30
31#990#7###71298#6#9####3##04#
###66###6######7#4#3#1079239#6
891###8#73#7#5838#589#225#1282
#####5#306#9#38#50##6#71##8658
6#68#4#5###30###3#5716987#####
06#8####3#####134#5##2##28#169
#5#11####0#75#8######28#6#904#
85#71####0##9#7#0##8#2##00####
#1#09#3772#838#67#6##261###0#4
#4##78###7#########9#9#488##08
43#1##4632##46714436##849#77#6
8#83#61##4#14476#9#1##72#3####
5#99####52##6#9####9#4#4132#3#
##910#27529#69##491###0#06#9##
0#60845#02##28##610#2####25#6#
#229156374##47#30907#60#####28
#0#810#54###21##1#3###8#5917##
###6#56#60##04#73###6255###2##
10
3 4 23
3 2 4
1 4 14
2 3 12
1 1 16
1 2 9
3 5 6
1 3 19
2 2 4
3 4 9
136
217
474
255
474
285
217
451
251
217
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。