Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ∧_∧
- ( ・ω・。)つ━☆・*。
- ⊂ ノ ・゜
- しーJ Accepted
- */
- #pragma GCC optimize("O3")
- // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #define ll long long
- #define all(x) begin(x), end(x)
- #define x first
- #define y second
- #define int long long
- #define pii pair<int, int>
- using namespace std;
- using namespace __gnu_pbds;
- typedef long double ld;
- template<typename T>
- using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
- const ld PI = atan2(0, -1);
- void seriy() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cout << fixed << setprecision(14);
- #ifdef _offline
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- }
- const int MAXN = 1e5 + 10;
- const int MAXM = 600;
- const int INF = 1e9;
- const int BASE = 47;
- const int MOD = 998244353;
- const int MAXLOG = 61;
- const ld EPS = 1e-8;
- vector<pair<string, int>> a;
- bool cor() {
- for(int i = 1; i < a.size(); i++) {
- // cerr << a[i - 1].x << " " << a[i].x << '\n';
- if(a[i].x == "LEFT" && a[i - 1].x == "RIGHT" ||
- a[i].x == "LEFT" && a[i - 1].x == "LEFT" ||
- a[i].x == "RIGHT" && a[i - 1].x == "RIGHT" ||
- a[i].x == "RIGHT" && a[i - 1].x == "LEFT" ||
- a[i].x == "TOP" && a[i - 1].x == "BOTTOM" ||
- a[i].x == "TOP" && a[i - 1].x == "TOP" ||
- a[i].x == "BOTTOM" && a[i - 1].x == "BOTTOM" ||
- a[i].x == "BOTTOM" && a[i - 1].x == "TOP") {
- return false;
- }
- }
- return true;
- }
- signed main() {
- seriy();
- string s;
- int num;
- while(cin >> s >> num) {
- a.push_back({s, num});
- }
- while(!cor()) {
- // cerr << '\n';
- vector<pair<string, int>> b;
- for(int i = 0; i < a.size(); i++) {
- int j = i;
- int cur = 0;
- bool was = 0;
- while(j < a.size() && (a[j].x == "LEFT" || a[j].x == "RIGHT")) {
- was = 1;
- if(a[j].x == "LEFT") {
- cur -= a[j].y;
- }
- else {
- cur += a[j].y;
- }
- j++;
- }
- if(was) {
- if(cur < 0) {
- b.push_back({"LEFT", -cur});
- }
- if(cur > 0) {
- b.push_back({"RIGHT", cur});
- }
- i = j - 1;
- continue;
- }
- cur = 0;
- was = 0;
- while(j < a.size() && (a[j].x == "TOP" || a[j].x == "BOTTOM")) {
- was = 1;
- if(a[j].x == "TOP") {
- cur -= a[j].y;
- }
- else {
- cur += a[j].y;
- }
- j++;
- }
- if(was) {
- if(cur < 0) {
- b.push_back({"TOP", -cur});
- }
- if(cur > 0) {
- b.push_back({"BOTTOM", cur});
- }
- i = j - 1;
- continue;
- }
- }
- a = b;
- }
- for(auto i : a) {
- cout << i.x << " " << i.y << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement