-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_.cpp
72 lines (59 loc) · 1.66 KB
/
_.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
using namespace std;
const int dr[9] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int dc[9] = {-1, -1, 0, 1, 1, 1, 0, -1, 0};
struct Pos {
int r, c, time;
};
string map[8];
bool visit[8][8];
// 캐릭터 먼저 이동함
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
for (int i = 0; i < 8; ++i) {
cin >> map[i];
}
queue<Pos> q;
q.push({7, 0, 0}); // map[7][0] 시작
visit[7][0] = true;
while (!q.empty()) {
memset(visit, false, sizeof(visit));
for (int i = 0; i < q.size(); ++i) {
Pos now = q.front();
q.pop();
if ((now.r == 0 && now.c == 7) || now.time == 8) { // map[0][7]
cout << 1;
return 0;
}
for (int i = 0; i < 9; ++i) {
Pos npos;
npos.r = now.r + dr[i];
npos.c = now.c + dc[i];
npos.time = now.time + 1;
if (npos.r < 0 || npos.c < 0 || npos.r >= 8 || npos.c >= 8) continue;
if (visit[npos.r][npos.c] || map[npos.r][npos.c] == '#') continue;
visit[npos.r][npos.c] = true;
q.push(npos);
}
}
// 벽이동
for (int i = 0; i < 8; ++i) {
map[7][i] = '.';
}
for (int i = 6; i >= 0; --i) {
for (int j = 0; j < 8; ++j) {
if (map[i][j] == '#') {
map[i][j] = '.';
map[i + 1][j] = '#';
}
}
}
}
cout << 0;
return 0;
}