-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy path2028A-AlicesAdventuresInChess.cpp
38 lines (32 loc) · 1.21 KB
/
2028A-AlicesAdventuresInChess.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
#include <iostream>
bool check(long x, long y, long a, long b, long xt, long yt){
if(xt == 0 && yt == 0){return x == a && y == b;}
else if(xt == 0){return (x == a && (b - y) % yt == 0 && (b - y) / yt > 0);}
else if(yt == 0){return (y == b && (a - x) % xt == 0 && (a - x) / xt > 0);}
else{return (a - x) % xt == 0 && (b - y) % yt == 0 && (a - x) / xt >= 0 && (a - x) / xt == (b - y) / yt;}
}
int main (){
std::ios_base::sync_with_stdio(false);
long t; std::cin >> t;
while(t--){
long n, a, b; std::cin >> n >> a >> b;
std::string s; std::cin >> s;
long xt(0), yt(0);
for(long p = 0; p < s.size(); p++){
if(s[p] == 'N'){++yt;}
else if(s[p] == 'S'){--yt;}
else if(s[p] == 'E'){++xt;}
else if(s[p] == 'W'){--xt;}
}
long x(0), y(0);
bool ans(check(0, 0, a, b, xt, yt));
for(long p = 0; p < s.size() && !ans; p++){
if(s[p] == 'N'){++y;}
else if(s[p] == 'S'){--y;}
else if(s[p] == 'E'){++x;}
else if(s[p] == 'W'){--x;}
if(check(x, y, a, b, xt, yt)){ans = true;}
}
std::cout << (ans ? "YES" : "NO") << std::endl;
}
}