Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
75 changes: 75 additions & 0 deletions flydongwoo/AlgoLeadMe_Week21_prob01.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include <iostream>
#include <queue>
#include <cstring>

#define MAX_SIZE 1000 + 1

using namespace std;

struct tomato {
int y, x;
};

queue<tomato> q;

// οΏ½οΏ½,οΏ½οΏ½,οΏ½οΏ½,οΏ½οΏ½
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };

int n, m, result = 0;
int graph[MAX_SIZE][MAX_SIZE];

bool IsInside(int ny, int nx) {
return (0 <= nx && 0 <= ny && nx < m && ny < n);
}

void bfs(void) {
while (!q.empty()) {
int y = q.front().y;
int x = q.front().x;
q.pop();

for (int i = 0; i < 4; i++) {
int ny = y + dy[i];
int nx = x + dx[i];

if (IsInside(ny, nx) == 1 && graph[ny][nx] == 0) {
graph[ny][nx] = graph[y][x] + 1;
q.push({ ny, nx });
}
}
}
}

int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);

cin >> m >> n;

for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> graph[i][j];
if (graph[i][j] == 1) {
q.push({ i, j });
}
}
}

bfs();

for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (graph[i][j] == 0) {
cout << -1 << "\n";
return 0;
}
if (result < graph[i][j]) {
result = graph[i][j];
}
}
}

cout << (result - 1) << endl;
return 0;
}
3 changes: 2 additions & 1 deletion flydongwoo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
| 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|