문제
import java.io.*;
import java.util.*;
// 모든 땅에는 폭탄값이 있음. (초기값 : 0)
// K개의 폭탄을 땅위에 떨어트리는데
// 폭탄이 떨어진 땅과 상하좌우로 인접한 칸의 폭탄값에 영향을 미침
// 맵 밖이거나, 땅이 #값이라면 변화 X
// 땅이 0이라면 폭탄 값은 1 증가
// 땅이 @이라면 폭탄 값은 2 증가
// 가장 높은 폭탄 값 출력
class Main {
static int N, K;
static char[][] mapStatus;
static int[][] mapValue;
static int[] deltaRow = {0, 0, 1, -1};
static int[] deltaCol = {1, -1, 0, 0};
static int max = Integer.MIN_VALUE;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
N = Integer.parseInt(st.nextToken());
K = Integer.parseInt(st.nextToken());
mapStatus = new char[N + 1][N + 1];
mapValue = new int[N + 1][N + 1];
for(int i = 1; i <= N; i++){
st = new StringTokenizer(br.readLine(), " ");
for(int j = 1; j <= N; j++){
mapStatus[i][j] = st.nextToken().charAt(0);
}
}
for(int i = 0; i < K; i++){
st = new StringTokenizer(br.readLine(), " ");
int bombRow = Integer.parseInt(st.nextToken());
int bombCol = Integer.parseInt(st.nextToken());
Bomb(bombRow, bombCol);
}
for(int i = 1; i <= N; i++){
for(int j = 1; j <= N; j++){
max = Math.max(max, mapValue[i][j]);
}
}
bw.write(String.valueOf(max));
bw.flush();
br.close();
bw.close();
}
public static void Bomb(int row, int col){
if(mapStatus[row][col] == '0'){
mapValue[row][col] += 1;
} else if(mapStatus[row][col] == '@'){
mapValue[row][col] += 2;
}
for(int i = 0; i < 4; i++){
int newRow = row + deltaRow[i];
int newCol = col + deltaCol[i];
if(newRow < 0 || newCol < 0 || newRow > N || newCol > N){
continue;
}
if(mapStatus[newRow][newCol] == '0'){
mapValue[newRow][newCol] += 1;
} else if(mapStatus[newRow][newCol] == '@'){
mapValue[newRow][newCol] += 2;
}
}
}
}