Algorithm/Baekjoon
[Algorithm]Baekjoon 16918번 :: 봄버맨
MaxLevel
2023. 5. 10. 14:24
https://www.acmicpc.net/problem/16918
16918번: 봄버맨
첫째 줄에 R, C, N (1 ≤ R, C, N ≤ 200)이 주어진다. 둘째 줄부터 R개의 줄에 격자판의 초기 상태가 주어진다. 빈 칸은 '.'로, 폭탄은 'O'로 주어진다.
www.acmicpc.net
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
struct Node
{
int y;
int x;
};
int dir[4][2] = { {-1,0}, {1,0}, {0,-1}, {0,1} };
char arr[201][201];
int r, c, n;
queue<Node> prevAddedNodes;
void print()
{
for (int i = 0; i < r; ++i)
{
for (int j = 0; j < c; ++j)
{
printf("%c", arr[i][j]);
}
printf("\n");
}
}
void setBomb()
{
for (int i = 0; i < r; ++i)
{
for (int j = 0; j < c; ++j)
{
if (arr[i][j] == '.')
{
arr[i][j] = 'O';
}
}
}
}
void explode()
{
while (!prevAddedNodes.empty())
{
int curY = prevAddedNodes.front().y;
int curX = prevAddedNodes.front().x;
prevAddedNodes.pop();
arr[curY][curX] = '.';
for (int i = 0; i < 4; ++i)
{
int nextY = curY + dir[i][0];
int nextX = curX + dir[i][1];
if (nextY < 0 || nextY >= r) continue;
if (nextX < 0 || nextX >= c) continue;
arr[nextY][nextX] = '.';
}
}
// 터트린다음 다음 터트릴거 저장.
for (int i = 0; i < r; ++i)
{
for (int j = 0; j < c; ++j)
{
if (arr[i][j] == 'O')
{
prevAddedNodes.push({ i,j });
}
}
}
}
int main(void)
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> r >> c >> n;
for (int i = 0; i < r; ++i)
{
for (int j = 0; j < c; ++j)
{
cin >> arr[i][j];
if (arr[i][j] == 'O')
{
prevAddedNodes.push({ i,j});
}
}
}
if (n == 1)
{
print();
return 0;
}
int time = 1;
while (1)
{
++time;
if (time > n) break;
if (time % 2 == 0) // 폭탄설치
{
setBomb();
}
else // 폭탄 폭발
{
explode();
}
}
print();
return 0;
}
|
cs |
time에 맞춰서 필요한만큼 체크하는식으로 깔끔하게 짜려했는데, 뭔가 뾰족한 수가 안떠올라서 그냥 필요할때마다 R*C 탐색하게 했다. 통과는 한다만, R이랑 C값이 매우 크면 아마... ANS를 못받을수도 있다