Skip to content

Commit abd6c0c

Browse files
committed
점프 게임
1 parent bab1ca8 commit abd6c0c

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

[Week18 - Search]/이현동/15558

90.7 KB
Binary file not shown.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int N, k;
5+
string arr[2];
6+
7+
bool OOB(int rx, int ry, int t)
8+
{
9+
if (0 <= rx && rx < 2 && t < ry && ry < N)
10+
return true;
11+
return false;
12+
}
13+
int bfs()
14+
{
15+
queue<pair<pair<int, int>, int>> q;
16+
int dx[] = {0, 0, 1, -1};
17+
int dy[] = {1, -1, k, k};
18+
19+
20+
bool visited[2][200001];
21+
fill(&visited[0][0], &visited[1][200000], false);
22+
23+
q.push({{0, 0}, 0});
24+
visited[0][0] = true;
25+
26+
while(!q.empty()){
27+
int x = q.front().first.first, y = q.front().first.second;
28+
int time = q.front().second;
29+
q.pop();
30+
if(time >= N)
31+
break;
32+
33+
for (int i = 0; i < 4;i++){
34+
int rx = x + dx[i];
35+
int ry = y + dy[i];
36+
if(ry >= N)
37+
return 1;
38+
if(OOB(rx, ry, time)){
39+
if (arr[rx][ry] == '1' && !visited[rx][ry] )
40+
{
41+
visited[rx][ry] = true;
42+
q.push({{rx, ry}, time + 1});
43+
}
44+
}
45+
}
46+
}
47+
return 0;
48+
}
49+
50+
int main()
51+
{
52+
53+
ios::sync_with_stdio(0);
54+
cin.tie(0);
55+
56+
cin >> N >> k;
57+
cin >> arr[0];
58+
cin >> arr[1];
59+
cout << bfs();
60+
61+
return 0;
62+
}

[Week18 - Search]/이현동/temp

Whitespace-only changes.

0 commit comments

Comments
 (0)