Skip to content

Commit d86f2e3

Browse files
committed
[Gold III] Title: 벽 부수고 이동하기, Time: 144 ms, Memory: 27972 KB -BaekjoonHub
1 parent 3a46c17 commit d86f2e3

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

백준/Gold/2206. 벽 부수고 이동하기/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
### 성능 요약
66

7-
메모리: 27972 KB, 시간: 160 ms
7+
메모리: 27972 KB, 시간: 144 ms
88

99
### 분류
1010

1111
그래프 이론, 그래프 탐색, 너비 우선 탐색, 격자 그래프
1212

1313
### 제출 일자
1414

15-
2025년 11월 12일 18:36:21
15+
2025년 11월 12일 18:38:12
1616

1717
### 문제 설명
1818

백준/Gold/2206. 벽 부수고 이동하기/벽 부수고 이동하기.cc

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ int maps[MAX][MAX]{};
1111
int visited[MAX][MAX][5]{};
1212
int dx[5] = {0, 0, 1, -1};
1313
int dy[5] = {1, -1, 0, 0};
14-
int flag = 0;
1514
int answer = 1e9;
1615

1716
void input() {
@@ -26,7 +25,7 @@ void input() {
2625
}
2726
}
2827

29-
void bfs() {
28+
int bfs() {
3029
queue<tuple<int, int, int, int>> q;
3130
q.push({1, 1, 1, 0}); // x, y, 거리, 벽 뚫은 여부
3231
visited[1][1][0] = 1;
@@ -40,8 +39,7 @@ void bfs() {
4039

4140
if (cx == N && cy == M) {
4241
answer = min(answer, dist);
43-
flag = 1;
44-
continue; // 도달하면, 더 진행할 필요 없잖아?
42+
return answer;
4543
}
4644

4745
for (int i = 0; i < 4; i++) {
@@ -60,18 +58,14 @@ void bfs() {
6058
}
6159
}
6260
}
61+
return -1;
6362
}
6463

6564
int main() {
6665
input();
6766

68-
bfs();
69-
70-
if (flag) {
71-
cout << answer;
72-
} else {
73-
cout << -1;
74-
}
67+
int answer = bfs();
68+
cout << answer;
7569

7670
return 0;
7771
}

0 commit comments

Comments
 (0)