Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.74 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. unordered_map<char, int> dx_transform = {{'W', -1}, {'S', 1}, {'A', 0}, {'D', 0}};
  6. unordered_map<char, int> dy_transform = {{'W', 0}, {'S', 0}, {'A', -1}, {'D', 1}};
  7.  
  8. struct state {
  9.     int prev_x = 0, prev_y = 0;
  10.     int curr_x = 0, curr_y = 0;
  11.    
  12. };
  13.  
  14. int main() {
  15.  
  16.     ios_base::sync_with_stdio(false);
  17.  
  18.     int t;
  19.     cin >> t;
  20.  
  21.     while (t--) {
  22.         string a;
  23.         cin >> a;
  24.  
  25.         int x = 0, y = 0;
  26.  
  27.         int min_x = 0, max_x = 0;
  28.         int min_y = 0, max_y = 0;
  29.        
  30.         int size = a.size();
  31.        
  32.         vector<pair<int,int>> mines;
  33.         vector<state> states;
  34.         vector<pair<int,int>> backward;
  35.  
  36.         for (char c : a) {
  37.             int prev_x = x, prev_y = y;
  38.            
  39.             x += dx_transform[c];
  40.             y += dy_transform[c];
  41.  
  42.             max_x = max(x, max_x);
  43.             min_x = min(x, min_x);
  44.  
  45.             max_y = max(y, max_y);
  46.             min_y = min(y, min_y);
  47.            
  48.             int curr_x = x, curr_y = y;
  49.            
  50.             states.push_back({prev_x, prev_y, curr_x, curr_y});
  51.             mines.push_back({min_x, min_y});
  52.         }
  53.        
  54.         int diff_x = abs(max_x - min_x) + 1;
  55.         int diff_y = abs(max_y - min_y) + 1;
  56.         int res = diff_x * diff_y;
  57.  
  58.         x = 0, y = 0;
  59.        
  60.         for (int i = size - 1; i >= 0; i--) {
  61.             char c = a[i];
  62.             x += dx_transform[c];
  63.             y += dy_transform[c];
  64.            
  65.             backward.push_back({x, y});
  66.         }
  67.        
  68.         for (state s : states) {
  69.             cout << s.prev_x << " " << s.prev_y << " CURR: " << s.curr_x << " " << s.curr_y << endl;
  70.    
  71.         }  
  72.        
  73.         for (int i = 0; i < size - 1; i++) {
  74.            
  75.             int maxx = 0, minx = 0;
  76.             int maxy = 0, miny = 0;
  77.            
  78.             maxx = max(maxx, states[i].curr_x);
  79.             maxx = max(maxx, states[i].prev_x);
  80.             minx = min(minx, states[i].curr_x);
  81.             minx = min(minx, states[i].prev_x);
  82.            
  83.             maxy = max(maxy, states[i].curr_y);
  84.             maxy = max(maxy, states[i].prev_y);
  85.             miny = min(miny, states[i].curr_y);
  86.             miny = min(miny, states[i].prev_y);
  87.            
  88.            
  89.            
  90.             maxx = max(maxx, states[i].prev_x + backward[i + 1].first);
  91.             maxy = max(maxy, states[i].curr_y);
  92.             maxy = max(maxy, states[i].prev_y + backward[i + 1].second);
  93.            
  94.            
  95.             int diff_x_tmp = abs(maxx - minx) + 1;
  96.             int diff_y_tmp = abs(maxy - miny) + 1;
  97.            
  98.             int tmp = diff_x_tmp * diff_y_tmp;
  99.            
  100.             cout << "COORDS " << maxx << " X " << minx << " " << maxy << " Y " << miny << endl;
  101.            
  102.             cout << diff_x_tmp << " " << diff_y_tmp << " " << tmp << endl;
  103.            
  104.             res = min(res, tmp);
  105.         }
  106.        
  107.         cout << endl;
  108.  
  109.  
  110.         cout << res << endl;
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement