diff --git a/flydongwoo/AlgoLeadMe_Week24_prob01.cpp b/flydongwoo/AlgoLeadMe_Week24_prob01.cpp new file mode 100644 index 0000000..9e6aa22 --- /dev/null +++ b/flydongwoo/AlgoLeadMe_Week24_prob01.cpp @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include + +using namespace std; + +int N, M; +vector board; +bool visited[1001][1001][2]; + +int dr[] = { -1, 1, 0, 0 }; +int dc[] = { 0, 0, -1, 1 }; + +int bfs() { + queue> 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; +} \ No newline at end of file diff --git a/flydongwoo/README.md b/flydongwoo/README.md index da77089..823607c 100644 --- a/flydongwoo/README.md +++ b/flydongwoo/README.md @@ -1,4 +1,4 @@ -## ✏️ 기록 +=## ✏️ 기록 | 차시 | 날짜 | 문제유형 | 링크 | 풀이 | |:----:|:---------:|:----:|:-----:|:----:| @@ -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|