diff --git a/flydongwoo/AlgoLeadMe_Week23_prob01.cpp b/flydongwoo/AlgoLeadMe_Week23_prob01.cpp new file mode 100644 index 0000000..907aedc --- /dev/null +++ b/flydongwoo/AlgoLeadMe_Week23_prob01.cpp @@ -0,0 +1,111 @@ +#include +#include +#include + +using namespace std; + +int R, C, T; +vector> room; +int purifier_top_r = -1; +int purifier_bottom_r = -1; + +int dr[] = { 0, 1, 0, -1 }; +int dc[] = { 1, 0, -1, 0 }; + +void spread_dust() { + vector> diffused_dust(R, vector(C, 0)); + + for (int r = 0; r < R; r++) { + for (int c = 0; c < C; c++) { + if (room[r][c] > 0) { + int spread_amount = room[r][c] / 5; + int spread_count = 0; + + for (int i = 0; i < 4; i++) { + int nr = r + dr[i]; + int nc = c + dc[i]; + + if (nr >= 0 && nr < R && nc >= 0 && nc < C && room[nr][nc] != -1) { + diffused_dust[nr][nc] += spread_amount; + spread_count++; + } + } + room[r][c] -= spread_amount * spread_count; + } + } + } + + for (int r = 0; r < R; r++) { + for (int c = 0; c < C; c++) { + room[r][c] += diffused_dust[r][c]; + } + } +} + +void circulate_air() { + for (int r = purifier_top_r - 1; r > 0; r--) { + room[r][0] = room[r - 1][0]; + } + for (int c = 0; c < C - 1; c++) { + room[0][c] = room[0][c + 1]; + } + for (int r = 0; r < purifier_top_r; r++) { + room[r][C - 1] = room[r + 1][C - 1]; + } + for (int c = C - 1; c > 1; c--) { + room[purifier_top_r][c] = room[purifier_top_r][c - 1]; + } + room[purifier_top_r][1] = 0; + + for (int r = purifier_bottom_r + 1; r < R - 1; r++) { + room[r][0] = room[r + 1][0]; + } + for (int c = 0; c < C - 1; c++) { + room[R - 1][c] = room[R - 1][c + 1]; + } + for (int r = R - 1; r > purifier_bottom_r; r--) { + room[r][C - 1] = room[r - 1][C - 1]; + } + for (int c = C - 1; c > 1; c--) { + room[purifier_bottom_r][c] = room[purifier_bottom_r][c - 1]; + } + room[purifier_bottom_r][1] = 0; +} + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + + cin >> R >> C >> T; + room.resize(R, vector(C)); + + for (int i = 0; i < R; i++) { + for (int j = 0; j < C; j++) { + cin >> room[i][j]; + if (room[i][j] == -1) { + if (purifier_top_r == -1) { + purifier_top_r = i; + purifier_bottom_r = i + 1; + } + } + } + } + + while (T--) { + spread_dust(); + circulate_air(); + } + + int total_dust = 0; + for (int i = 0; i < R; i++) { + for (int j = 0; j < C; j++) { + if (room[i][j] > 0) { + total_dust += room[i][j]; + } + } + } + + cout << total_dust << endl; + + return 0; +} \ No newline at end of file diff --git a/flydongwoo/README.md b/flydongwoo/README.md index da77089..5f1de2d 100644 --- a/flydongwoo/README.md +++ b/flydongwoo/README.md @@ -21,4 +21,7 @@ | 17차시 | 2025.08.06 | DFS와 BFS | [바이러스](https://www.acmicpc.net/problem/2606)|https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/63| | 18차시 | 2025.08.07 | BFS | [숨바꼭질](https://www.acmicpc.net/problem/1697)|https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/64| | 19차시 | 2025.08.14 | Sliding Window | [수열](https://www.acmicpc.net/problem/2559)|https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/71| - +| 20차시 | 2025.08.27 | Greedy Algorithm | [ATM](https://www.acmicpc.net/problem/11399)|https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/81| +| 21차시 | 2025.08.28 | BFS | [토마토](https://www.acmicpc.net/problem/7576)|https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/82| +| 22차시 | 2025.09.05 | 시뮬레이션 | [로봇 청소기](https://www.acmicpc.net/problem/14503)|https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/87| +| 23차시 | 2025.09.06 | 시뮬레이션 | [미세먼지 안녕!](https://www.acmicpc.net/problem/17144)|https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/88|