Advertisement
pedrocasdev

Untitled

Aug 29th, 2022
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. using namespace __gnu_pbds;
  5. using namespace std;
  6.  
  7. #define ordered_set tree<pair<int, int>, null_type,less<pair<int, int>>, rb_tree_tag,tree_order_statistics_node_update>
  8. typedef long long ll;
  9. const long long mod = 1000000007;
  10. ll gcd (ll a, ll b) {return b==0 ? a : gcd(b, a%b);}
  11.  
  12. #define all(c) (c).begin(),(c).end()
  13. #define pb push_back
  14. #define mp make_pair
  15. #define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
  16. #define debug_vector(v, n) for(int i = 0; i<n; i++)cout<< v[i] << " \n"[i == n-1]
  17. #define forn(i, n) for (int i = 0; i < n; i++)
  18.  
  19. const int di4[] = {-1, 0, 1,  0};
  20. const int dj4[] = { 0, 1, 0, -1};
  21. const int di8[] = {-1, 0, 1,  0, -1, 1,-1,1};
  22. const int dj8[] = { 0, 1, 0, -1, -1, 1,1,-1};
  23.  
  24. const int maxn = 4e4;
  25. struct hash_pair {
  26.     template <class T1, class T2>
  27.     size_t operator()(const pair<T1, T2>& p) const
  28.     {
  29.         auto hash1 = hash<T1>{}(p.first);
  30.         auto hash2 = hash<T2>{}(p.second);
  31.  
  32.         if (hash1 != hash2) {
  33.             return hash1 ^ hash2;            
  34.         }
  35.          
  36.          return hash1;
  37.     }
  38. };
  39. unordered_map<pair<int, int>, bool, hash_pair> vis;
  40. int main()
  41. {
  42. #ifdef LOCAL
  43.     freopen("input.txt", "rt", stdin);
  44.     freopen("output.txt", "wt", stdout);
  45. #endif
  46.     map<char, pair<int, int>> dir;
  47.     dir['N'] = {-1, 0}, dir['S'] = {1, 0}, dir['W'] = {0, -1}, dir['E'] = {0, 1};
  48.     fastio
  49.     int tc;
  50.     cin >> tc;
  51.     int cs = 1;
  52.     while(tc--){
  53.         string s;
  54.         int r, c, n, sr, sc;
  55.         cin >> n >> r >> c >> sr >> sc;
  56.         cin >> s;
  57.         vis[{sr, sc}] = true;
  58.         int i = sr, j = sc;
  59.         for(char x : s){
  60.             i = i + dir[x].first, j  = j + dir[x].second;
  61.             //cout << dir[x].first<<" "<<dir[x].second<<endl;
  62.             while(vis[{i, j}]){
  63.                 i = i + dir[x].first, j = j + dir[x].second;
  64.             }
  65.             vis[{i, j}] = true;
  66.         }
  67.         cout <<"Case #" <<cs << ": "<< i << " " << j<<endl;
  68.         vis.clear();
  69.         ++cs;
  70.     }
  71.     return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement