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
63 changes: 63 additions & 0 deletions flydongwoo/AlgoLeadMe_Week24_prob01.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <tuple>

using namespace std;

int N, M;
vector<string> board;
bool visited[1001][1001][2];

int dr[] = { -1, 1, 0, 0 };
int dc[] = { 0, 0, -1, 1 };

int bfs() {
queue<tuple<int, int, int, bool>> q;

q.push({ 0, 0, 1, false });
visited[0][0][0] = true;

while (!q.empty()) {
auto [r, c, dist, broken] = q.front();
q.pop();

if (r == N - 1 && c == M - 1) {
return dist;
}

for (int i = 0; i < 4; i++) {
int nr = r + dr[i];
int nc = c + dc[i];

if (nr >= 0 && nr < N && nc >= 0 && nc < M) {
if (board[nr][nc] == '0' && !visited[nr][nc][broken]) {
visited[nr][nc][broken] = true;
q.push({ nr, nc, dist + 1, broken });
}
else if (board[nr][nc] == '1' && !broken) {
visited[nr][nc][1] = true;
q.push({ nr, nc, dist + 1, true });
}
}
}
}

return -1;
}

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);

cin >> N >> M;
board.resize(N);
for (int i = 0; i < N; i++) {
cin >> board[i];
}

cout << bfs() << endl;

return 0;
}
8 changes: 6 additions & 2 deletions flydongwoo/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## โœ๏ธ ๊ธฐ๋ก
=## โœ๏ธ ๊ธฐ๋ก

| ์ฐจ์‹œ | ๋‚ ์งœ | ๋ฌธ์ œ์œ ํ˜• | ๋งํฌ | ํ’€์ด |
|:----:|:---------:|:----:|:-----:|:----:|
Expand All @@ -21,4 +21,8 @@
| 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|
| 24์ฐจ์‹œ | 2025.09.07 | BFS | [๋ฒฝ ๋ถ€์ˆ˜๊ณ  ์ด๋™ํ•˜๊ธฐ](https://www.acmicpc.net/problem/2206)|https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/89|