From 68298e0f50b8e95362121b459364ad2a3090f647 Mon Sep 17 00:00:00 2001 From: oncsr Date: Fri, 21 Feb 2025 09:18:25 +0900 Subject: [PATCH] =?UTF-8?q?[20250221]=20BOJ=20/=20G2=20/=20=ED=99=95?= =?UTF-8?q?=EC=9E=A5=20=EA=B2=8C=EC=9E=84=20/=20=EA=B6=8C=ED=98=81?= =?UTF-8?q?=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5\354\236\245 \352\262\214\354\236\204.md" | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 "khj20006/202502/21 BOJ G2 \355\231\225\354\236\245 \352\262\214\354\236\204.md" diff --git "a/khj20006/202502/21 BOJ G2 \355\231\225\354\236\245 \352\262\214\354\236\204.md" "b/khj20006/202502/21 BOJ G2 \355\231\225\354\236\245 \352\262\214\354\236\204.md" new file mode 100644 index 00000000..129d5020 --- /dev/null +++ "b/khj20006/202502/21 BOJ G2 \355\231\225\354\236\245 \352\262\214\354\236\204.md" @@ -0,0 +1,60 @@ +```cpp + +#include +#include +#include +using namespace std; + +int N, M, P, A[1000][1000]{}, S[10]{}; +int dx[4] = { 1,0,-1,0 }; +int dy[4] = { 0,1,0,-1 }; + +int main() +{ + cin.tie(0)->sync_with_stdio(0); + + cin >> N >> M >> P; + for (int i = 1; i <= P; i++) cin >> S[i]; + for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) { + char a; + cin >> a; + if (a == '.') continue; + if (a == '#') A[i][j] = -1; + else A[i][j] = a - '0'; + } + + queue> Q[10]{}; + for (int p = 1; p <= P; p++) { + 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]); + } + + while (true) { + + bool change = false; + queue> NQ[10]{}; + for (int p = 1; p <= P; p++) { + while (!Q[p].empty()) { + auto[x, y, t] = Q[p].front(); + Q[p].pop(); + for (int k = 0; k < 4; k++) { + int xx = x + dx[k], yy = y + dy[k]; + if (xx < 0 || xx >= N || yy < 0 || yy >= M || A[xx][yy]) continue; + change = true; + A[xx][yy] = p; + if (t > 1) Q[p].emplace(xx, yy, t - 1); + else NQ[p].emplace(xx, yy, S[p]); + } + } + } + if (!change) break; + for (int p = 1; p <= P; p++) Q[p] = NQ[p]; + + } + + int cnt[10]{}; + 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; + for (int i = 1; i <= P; i++) cout << cnt[i] << ' '; + +} + +```