Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- unordered_map<char, int> dx_transform = {{'W', -1}, {'S', 1}, {'A', 0}, {'D', 0}};
- unordered_map<char, int> dy_transform = {{'W', 0}, {'S', 0}, {'A', -1}, {'D', 1}};
- struct state {
- int prev_x = 0, prev_y = 0;
- int curr_x = 0, curr_y = 0;
- };
- int main() {
- ios_base::sync_with_stdio(false);
- int t;
- cin >> t;
- while (t--) {
- string a;
- cin >> a;
- int x = 0, y = 0;
- int min_x = 0, max_x = 0;
- int min_y = 0, max_y = 0;
- int size = a.size();
- vector<pair<int,int>> mines;
- vector<state> states;
- vector<pair<int,int>> backward;
- for (char c : a) {
- int prev_x = x, prev_y = y;
- x += dx_transform[c];
- y += dy_transform[c];
- max_x = max(x, max_x);
- min_x = min(x, min_x);
- max_y = max(y, max_y);
- min_y = min(y, min_y);
- int curr_x = x, curr_y = y;
- states.push_back({prev_x, prev_y, curr_x, curr_y});
- mines.push_back({min_x, min_y});
- }
- int diff_x = abs(max_x - min_x) + 1;
- int diff_y = abs(max_y - min_y) + 1;
- int res = diff_x * diff_y;
- x = 0, y = 0;
- for (int i = size - 1; i >= 0; i--) {
- char c = a[i];
- x += dx_transform[c];
- y += dy_transform[c];
- backward.push_back({x, y});
- }
- for (state s : states) {
- cout << s.prev_x << " " << s.prev_y << " CURR: " << s.curr_x << " " << s.curr_y << endl;
- }
- for (int i = 0; i < size - 1; i++) {
- int maxx = 0, minx = 0;
- int maxy = 0, miny = 0;
- maxx = max(maxx, states[i].curr_x);
- maxx = max(maxx, states[i].prev_x);
- minx = min(minx, states[i].curr_x);
- minx = min(minx, states[i].prev_x);
- maxy = max(maxy, states[i].curr_y);
- maxy = max(maxy, states[i].prev_y);
- miny = min(miny, states[i].curr_y);
- miny = min(miny, states[i].prev_y);
- maxx = max(maxx, states[i].prev_x + backward[i + 1].first);
- maxy = max(maxy, states[i].curr_y);
- maxy = max(maxy, states[i].prev_y + backward[i + 1].second);
- int diff_x_tmp = abs(maxx - minx) + 1;
- int diff_y_tmp = abs(maxy - miny) + 1;
- int tmp = diff_x_tmp * diff_y_tmp;
- cout << "COORDS " << maxx << " X " << minx << " " << maxy << " Y " << miny << endl;
- cout << diff_x_tmp << " " << diff_y_tmp << " " << tmp << endl;
- res = min(res, tmp);
- }
- cout << endl;
- cout << res << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement