Skip to content

Commit edcb32d

Browse files
authored
Merge pull request #161 from AlgorithmWithGod/khj20006
[20250221] BOJ / G2 / 확장 게임 / 권혁준
2 parents 30eb3fb + 68298e0 commit edcb32d

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
```cpp
2+
3+
#include <iostream>
4+
#include <tuple>
5+
#include <queue>
6+
using namespace std;
7+
8+
int N, M, P, A[1000][1000]{}, S[10]{};
9+
int dx[4] = { 1,0,-1,0 };
10+
int dy[4] = { 0,1,0,-1 };
11+
12+
int main()
13+
{
14+
cin.tie(0)->sync_with_stdio(0);
15+
16+
cin >> N >> M >> P;
17+
for (int i = 1; i <= P; i++) cin >> S[i];
18+
for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) {
19+
char a;
20+
cin >> a;
21+
if (a == '.') continue;
22+
if (a == '#') A[i][j] = -1;
23+
else A[i][j] = a - '0';
24+
}
25+
26+
queue<tuple<int, int, int>> Q[10]{};
27+
for (int p = 1; p <= P; p++) {
28+
for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) if (A[i][j] == p) Q[p].emplace(i, j, S[p]);
29+
}
30+
31+
while (true) {
32+
33+
bool change = false;
34+
queue<tuple<int, int, int>> NQ[10]{};
35+
for (int p = 1; p <= P; p++) {
36+
while (!Q[p].empty()) {
37+
auto[x, y, t] = Q[p].front();
38+
Q[p].pop();
39+
for (int k = 0; k < 4; k++) {
40+
int xx = x + dx[k], yy = y + dy[k];
41+
if (xx < 0 || xx >= N || yy < 0 || yy >= M || A[xx][yy]) continue;
42+
change = true;
43+
A[xx][yy] = p;
44+
if (t > 1) Q[p].emplace(xx, yy, t - 1);
45+
else NQ[p].emplace(xx, yy, S[p]);
46+
}
47+
}
48+
}
49+
if (!change) break;
50+
for (int p = 1; p <= P; p++) Q[p] = NQ[p];
51+
52+
}
53+
54+
int cnt[10]{};
55+
for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) for (int p = 1; p <= P; p++) cnt[p] += A[i][j] == p;
56+
for (int i = 1; i <= P; i++) cout << cnt[i] << ' ';
57+
58+
}
59+
60+
```

0 commit comments

Comments
 (0)