"Title description"
Allied scientists found that the proton impact cannon has an energy transfer characteristics, the proton energy will make the fence chain reaction, a series of explosions, will be in the upper and lower left and right four directions (no oblique direction) to produce a little splash damage, if the fence is connected in four directions, will be blown together, four directions are caused by 1 points of sputtering damage. This topic has made some improvements to the proton shells, which will be read into a 5*5 damage matrix, which is the center of the landing point.
"Input description"
First line: N (n <= 20);
2nd to n+1: A n*n topographic map of the enemy;
Next five elements: a 5*5 damage matrix (3,3) as the center, that is, the landing point;
Next five elements: the center of the landing point of the V-rounds (x, y).
(in N*n's enemy topographic map, 0 means open space, 1 represents the fence, and 1~9 represents the building's blood volume.) )
"Output description"
Two numbers, the first to destroy the number of buildings, the second to destroy the number of walls.
"Sample Input"
5
0 0 1) 4 1
-1-1-1-1-1
-1 2 1 0 4
1 9 4) 2 1
0 0 0) 0 0
0 0 0) 0 0
0 1 1) 1 0
0 1 2) 1 0
0 1 1) 1 0
0 0 0) 0 0
2 3
4 4
5 3
3 4
5 5
"Sample Output"
9
6
"Data range and Tips"
Sample Resolution: X indicates a building explosion, y indicates a wall explosion.
First cannon:
0 0 x 3 x
Y y x y y y
Y x x 0 3
X 8 3 2 1
0 0 0) 0 0
Second gun:
0 0 x 3 x
Y y x y y y
Y x x 0 2
X 8 2 x x
0 0 0) 0 0
Third cannon:
0 0 x 3 x
Y y x y y y
Y x x 0 x
X 8 2 x x
0 0 0) 0 0
Four cannon:
0 0 x 3 x
Y y x y y y
Y x x 0 x
x 7 x x x
0 0 0) 0 0
V Cannon:
0 0 x 3 x
Y y x y y y
Y x x 0 x
x 7 x x x
0 0 0) 0 0
Proton Impact cannon