import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
static int[] dr = {-1, 1, 0, 0};
static int[] dc = {0, 0, -1, 1};
static int R, C, N;
static int[][] map;
public static void main(String[] args) throws IOException {
init();
if (N % 2 == 0) {
set(N);
} else {
// n 초에 터지게 값 저장
for (int n = 2; n <= N; n++) {
N = N % 4 + 4;
// 폭탄 설치
if (n % 2 == 0) {
set(n);
} else {
bomb(n);
}
}
}
printArray();
}
private static void init() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
R = Integer.parseInt(st.nextToken());
C = Integer.parseInt(st.nextToken());
N = Integer.parseInt(st.nextToken());
map = new int[R][C];
for (int i = 0; i < R; i++) {
String s = br.readLine();
for (int j = 0; j < C; j++) {
if (s.charAt(j) == '.') {
map[i][j] = 0;
} else {
map[i][j] = 3;
}
}
}
}
private static void set(int n) {
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
if (map[i][j] == 0) map[i][j] = n + 3;
}
}
}
private static void bomb(int n) {
for (int r = 0; r < R; r++) {
for (int c = 0; c < C; c++) {
if (map[r][c] == n) {
map[r][c] = 0;
for (int i = 0; i < 4; i++) {
int nr = r + dr[i];
int nc = c + dc[i];
if (nr < 0 || nc < 0 || nr >= R || nc >= C) continue;
if (map[nr][nc] == n) continue;
map[nr][nc] = 0;
}
}
}
}
}
private static void printArray() {
for (int[] ints : map) {
for (int i : ints) {
if (i == 0) System.out.print(".");
else System.out.print("O");
}
System.out.println();
}
}
}
N
의 값을 증가시켜서 출력해볼 것N
의 크기가 굉장히 큰 문제N
의 크기로 인해, N
을 조작하지 않으면 시간초과가 발생하는 문제N
이 짝수인 경우와 홀수인 경우가 다르다 (2초마다 폭탄 설치, 3초마다 폭탄 폭파)N
까지 반복 수행짝수인 경우는 다 채운다음 바로 출력
홀수인 경우는 반복문 수행
N %= 4
로 하면 끝이겠네' 하면, 예제만 맞고 틀린다 2 2 11
.O
O.
==========2==========
OO
OO
==========3==========
..
..
==========4==========
OO
OO
==========5==========
OO
OO
==========6==========
OO
OO
==========7==========
..
..
==========8==========
OO
OO
==========9==========
OO
OO
==========10==========
OO
OO
==========11==========
..
..
N
을 다음과 같이 조작하면 됨N = N % 4 + 4
N
의 값은 7이 되며, 이후로는 값이 계속해서 반복되게 되므로, 우리는 7까지의 결과만 알면 된다.N
의 크기가 한자리로 줄어들게되어, 시간초과가 나지 않으며, 모든 경우에 대해서도 정상적으로 동작하게됨