-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrow Path.cpp
More file actions
80 lines (61 loc) · 2.28 KB
/
Copy pathArrow Path.cpp
File metadata and controls
80 lines (61 loc) · 2.28 KB
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
73
74
75
76
77
78
79
80
#include <bits/stdc++.h>
#define mt(a, b, c) make_pair(a, make_pair(b, c))
using namespace std;
int casos, n;
char matriz[3][200005];
bool visitado[2][3][200005];
int adyx[4] = {0, 0, 1, -1};
int adyy[4] = {-1, 1, 0, 0};
queue<pair<bool, pair<int, int> > > cola;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> casos;
while(casos --){
cin >> n;
for(int i = 1; i <= 2; i ++){
for(int j = 1; j <= n; j ++){
cin >> matriz[i][j];
}
}
cola.push(mt(false, 1, 1));
visitado[1][1][1] = true;
while(!cola.empty()){
bool a = cola.front().first;
int x = cola.front().second.first;
int y = cola.front().second.second;
cola.pop();
if(x == 2 && y == n) break;
if(a == false){
for(int i = 0; i < 4; i ++){
int xx = x + adyx[i];
int yy = y + adyy[i];
if(xx >= 1 && xx <= 2 && yy >= 1 && yy <= n && visitado[true][xx][yy] == false){
visitado[true][xx][yy] = true;
cola.push(mt(true, xx, yy));
}
}
}
else{
if(matriz[x][y] == '<' && visitado[false][x][y - 1] == false){
cola.push(mt(false, x, y - 1));
visitado[false][x][y - 1] = true;
}
else if(matriz[x][y] == '>' && visitado[false][x][y + 1] == false){
cola.push(mt(false, x, y + 1));
visitado[false][x][y + 1] = true;
}
}
}
if(visitado[false][2][n] == true || visitado[true][2][n] == true) cout << "YES\n";
else cout << "NO\n";
while(!cola.empty()) cola.pop();
for(int i = 1; i <= 2; i ++){
for(int j = 1; j <= n; j ++){
visitado[false][i][j] = visitado[true][i][j] = false;
}
}
}
return 0;
}