Advertisement
GerONSo

Untitled

Feb 9th, 2021
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. /*
  2.  
  3. ∧_∧
  4. ( ・ω・。)つ━☆・*。
  5. ⊂  ノ    ・゜
  6. しーJ   Accepted
  7.  
  8. */
  9.  
  10.  
  11.  
  12. #pragma GCC optimize("O3")
  13. // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  14.  
  15. #include <bits/stdc++.h>
  16. #include <ext/pb_ds/assoc_container.hpp>
  17. #include <ext/pb_ds/tree_policy.hpp>
  18.  
  19. #define ll long long
  20. #define all(x) begin(x), end(x)
  21. #define x first
  22. #define y second
  23. #define int long long
  24. #define pii pair<int, int>
  25.  
  26. using namespace std;
  27. using namespace __gnu_pbds;
  28.  
  29. typedef long double ld;
  30. template<typename T>
  31. using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  32.  
  33. const ld PI = atan2(0, -1);
  34.  
  35. void seriy() {
  36. ios::sync_with_stdio(0);
  37. cin.tie(0);
  38. cout.tie(0);
  39. cout << fixed << setprecision(14);
  40. #ifdef _offline
  41. freopen("input.txt", "r", stdin);
  42. freopen("output.txt", "w", stdout);
  43. #endif
  44. }
  45.  
  46. const int MAXN = 1e5 + 10;
  47. const int MAXM = 600;
  48. const int INF = 1e9;
  49. const int BASE = 47;
  50. const int MOD = 998244353;
  51. const int MAXLOG = 61;
  52. const ld EPS = 1e-8;
  53.  
  54. vector<pair<string, int>> a;
  55.  
  56. bool cor() {
  57. for(int i = 1; i < a.size(); i++) {
  58. // cerr << a[i - 1].x << " " << a[i].x << '\n';
  59. if(a[i].x == "LEFT" && a[i - 1].x == "RIGHT" ||
  60. a[i].x == "LEFT" && a[i - 1].x == "LEFT" ||
  61. a[i].x == "RIGHT" && a[i - 1].x == "RIGHT" ||
  62. a[i].x == "RIGHT" && a[i - 1].x == "LEFT" ||
  63. a[i].x == "TOP" && a[i - 1].x == "BOTTOM" ||
  64. a[i].x == "TOP" && a[i - 1].x == "TOP" ||
  65. a[i].x == "BOTTOM" && a[i - 1].x == "BOTTOM" ||
  66. a[i].x == "BOTTOM" && a[i - 1].x == "TOP") {
  67. return false;
  68. }
  69. }
  70. return true;
  71. }
  72.  
  73. signed main() {
  74. seriy();
  75. string s;
  76. int num;
  77. while(cin >> s >> num) {
  78. a.push_back({s, num});
  79. }
  80. while(!cor()) {
  81. // cerr << '\n';
  82. vector<pair<string, int>> b;
  83. for(int i = 0; i < a.size(); i++) {
  84. int j = i;
  85. int cur = 0;
  86. bool was = 0;
  87. while(j < a.size() && (a[j].x == "LEFT" || a[j].x == "RIGHT")) {
  88. was = 1;
  89. if(a[j].x == "LEFT") {
  90. cur -= a[j].y;
  91. }
  92. else {
  93. cur += a[j].y;
  94. }
  95. j++;
  96. }
  97. if(was) {
  98. if(cur < 0) {
  99. b.push_back({"LEFT", -cur});
  100. }
  101. if(cur > 0) {
  102. b.push_back({"RIGHT", cur});
  103. }
  104. i = j - 1;
  105. continue;
  106. }
  107.  
  108. cur = 0;
  109. was = 0;
  110. while(j < a.size() && (a[j].x == "TOP" || a[j].x == "BOTTOM")) {
  111. was = 1;
  112. if(a[j].x == "TOP") {
  113. cur -= a[j].y;
  114. }
  115. else {
  116. cur += a[j].y;
  117. }
  118. j++;
  119. }
  120. if(was) {
  121. if(cur < 0) {
  122. b.push_back({"TOP", -cur});
  123. }
  124. if(cur > 0) {
  125. b.push_back({"BOTTOM", cur});
  126. }
  127. i = j - 1;
  128. continue;
  129. }
  130. }
  131. a = b;
  132. }
  133. for(auto i : a) {
  134. cout << i.x << " " << i.y << '\n';
  135. }
  136. return 0;
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement