Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions flydongwoo/AlgoLeadMe_Week23_prob01.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int R, C, T;
vector<vector<int>> 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<vector<int>> diffused_dust(R, vector<int>(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<int>(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;
}
5 changes: 4 additions & 1 deletion flydongwoo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|