Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace __gnu_pbds;
- using namespace std;
- #define ordered_set tree<pair<int, int>, null_type,less<pair<int, int>>, rb_tree_tag,tree_order_statistics_node_update>
- typedef long long ll;
- const long long mod = 1000000007;
- ll gcd (ll a, ll b) {return b==0 ? a : gcd(b, a%b);}
- #define all(c) (c).begin(),(c).end()
- #define pb push_back
- #define mp make_pair
- #define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
- #define debug_vector(v, n) for(int i = 0; i<n; i++)cout<< v[i] << " \n"[i == n-1]
- #define forn(i, n) for (int i = 0; i < n; i++)
- const int di4[] = {-1, 0, 1, 0};
- const int dj4[] = { 0, 1, 0, -1};
- const int di8[] = {-1, 0, 1, 0, -1, 1,-1,1};
- const int dj8[] = { 0, 1, 0, -1, -1, 1,1,-1};
- const int maxn = 4e4;
- struct hash_pair {
- template <class T1, class T2>
- size_t operator()(const pair<T1, T2>& p) const
- {
- auto hash1 = hash<T1>{}(p.first);
- auto hash2 = hash<T2>{}(p.second);
- if (hash1 != hash2) {
- return hash1 ^ hash2;
- }
- return hash1;
- }
- };
- unordered_map<pair<int, int>, bool, hash_pair> vis;
- int main()
- {
- #ifdef LOCAL
- freopen("input.txt", "rt", stdin);
- freopen("output.txt", "wt", stdout);
- #endif
- map<char, pair<int, int>> dir;
- dir['N'] = {-1, 0}, dir['S'] = {1, 0}, dir['W'] = {0, -1}, dir['E'] = {0, 1};
- fastio
- int tc;
- cin >> tc;
- int cs = 1;
- while(tc--){
- string s;
- int r, c, n, sr, sc;
- cin >> n >> r >> c >> sr >> sc;
- cin >> s;
- vis[{sr, sc}] = true;
- int i = sr, j = sc;
- for(char x : s){
- i = i + dir[x].first, j = j + dir[x].second;
- //cout << dir[x].first<<" "<<dir[x].second<<endl;
- while(vis[{i, j}]){
- i = i + dir[x].first, j = j + dir[x].second;
- }
- vis[{i, j}] = true;
- }
- cout <<"Case #" <<cs << ": "<< i << " " << j<<endl;
- vis.clear();
- ++cs;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement