forked from tony9402/baekjoon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
59 lines (55 loc) · 1.38 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Authored by : seastar105
// Co-authored by : -
// Link : http://boj.kr/f78a96ebfe9a42648e1e0bc67255916a
#include<bits/stdc++.h>
using namespace std;
int R, C, N;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
vector<string> a(201);
int fire_time[201][201];
bool valid(int x, int y) {
return 0<=x && x<R && 0<=y && y<C;
}
void fire(int t) {
for(int i=0;i<R;++i) {
for(int j=0;j<C;++j) {
if(fire_time[i][j] != t) continue;
for(int k=0;k<4;++k) {
int nx = i + dx[k];
int ny = j + dy[k];
if(!valid(nx, ny)) continue;
if(fire_time[nx][ny] == t) continue;
fire_time[nx][ny] = 0;
a[nx][ny] = '.';
}
fire_time[i][j] = 0;
a[i][j] = '.';
}
}
}
void set_all(int t) {
for(int i=0;i<R;++i) {
for(int j=0;j<C;++j) {
if(a[i][j] == 'O') continue;
a[i][j] = 'O';
fire_time[i][j] = t+3;
}
}
}
int main() {
cin.tie(nullptr); ios::sync_with_stdio(false);
cin >> R >> C >> N;
for(int i=0;i<R;++i) {
cin >> a[i];
for(int j=0;j<C;++j) {
if(a[i][j] == 'O') fire_time[i][j] = 3;
}
}
for(int t=2;t<=N;++t) {
if(t%2) fire(t);
else set_all(t);
}
for(int i=0;i<R;++i) cout << a[i] << '\n';
return 0;
}