fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #ifdef LOCAL
  5. #include "debug.cpp"
  6. #else
  7. #define debug(...)
  8. #define debugArr(...)
  9. #endif
  10.  
  11. #define C make_pair
  12. #define all(a) (a).begin(), (a).end()
  13. #define el '\n'
  14. #define rep(i, n) for (int i = 0, _n = (n); i < _n; ++i)
  15. #define forn(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
  16. #define ford(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
  17. #define fi first
  18. #define se second
  19. #define eb emplace_back
  20. #define MASK(i) (1LL << (i))
  21. #define getbit(x, y) (((x) >> (y)) & 1LL)
  22. #define turnon(x, y) ((x) | MASK(y))
  23. #define turnoff(x, y) ((x) & ~MASK(y))
  24. #define flipbit(x, y) ((x) ^ MASK(y))
  25. #define bitcnt(x) __builtin_popcountll(x)
  26. #define TIME (1.0 * clock() / CLOCKS_PER_SEC)
  27.  
  28. typedef long double ld;
  29. typedef long long ll;
  30. typedef pair<int, int> ii;
  31. typedef vector<int> vi;
  32. typedef vector<vector<int>> vii;
  33. typedef vector<vii> viii;
  34.  
  35. inline int readInt(){ char c; while (c = getchar(), c != '-' && !isdigit(c)); int n, s = (c == '-' ? -1 : 1);
  36. n = s < 0 ? 0 : c - 48; while (c = getchar(), isdigit(c)) n = (n << 3) + (n << 1) + c - 48; return n * s; }
  37.  
  38. inline string readString(){ char c; while (c = getchar(), c == ' ' || c == '\n' || c == '\t');
  39. string s({c}); while (c = getchar(), c != EOF && c != ' ' && c != '\n' && c != '\t') s += c; return s; }
  40.  
  41. template <class X, class Y> inline bool maximize(X &a, const Y &b){ return (a < b ? a = b, true : false); }
  42. template <class X, class Y> inline bool minimize(X &a, const Y &b){ return (a > b ? a = b, true : false); }
  43.  
  44. const int MAX = 1e6 + 5;
  45.  
  46. string s;
  47. int i;
  48. int power[3], sum[3];
  49.  
  50. void skip() {
  51. while (s[i] == ' ') i++;
  52. }
  53.  
  54. int inp() {
  55. int ans = 0;
  56. skip();
  57. while (s[i] <= '9' && s[i] >= '0') {
  58. ans = ans * 10 + (s[i] - '0');
  59. i++;
  60. skip();
  61. }
  62. return ans;
  63. }
  64.  
  65. void pos(int idx) {
  66. if (s[i] == '+') {
  67. i++;
  68. sum[idx] = inp();
  69. } else if (s[i] == '-') {
  70. i++;
  71. sum[idx] = -inp();
  72. } else if (s[i] == '*') {
  73. i++;
  74. power[idx] = inp();
  75. }
  76. }
  77.  
  78. vi build() {
  79. vi v;
  80. while (s[i] != '[') i++;
  81. i++;
  82. int tmp = inp();
  83. v.push_back(tmp);
  84. if (s[i] == '.') {
  85. i += 2;
  86. int r = inp();
  87. for (int j = tmp + 1; j <= r; j++) v.push_back(j);
  88. } else {
  89. while (s[i] != ']') {
  90. i++;
  91. v.push_back(inp());
  92. }
  93. }
  94. return v;
  95. }
  96.  
  97. void solve() {
  98. getline(cin, s);
  99. s = " " + s;
  100. i = 4;
  101. sum[1] = sum[2] = 0;
  102. power[1] = power[2] = 1;
  103. pos(1);i++;
  104. skip();i++;
  105. pos(2);
  106. vi a = build(), b = build();
  107. cout << "[";
  108. int sz = a.size() * b.size();
  109. for (int x : a) {
  110. for (int y : b) {
  111. cout << "(" << x * power[1] + sum[1] << "," << y * power[2] + sum[2] << ")";
  112. sz--;
  113. if (sz > 0) cout << ",";
  114. }
  115. }
  116. cout << "]";
  117. }
  118.  
  119. signed main() {
  120. ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  121.  
  122. #define name "tree"
  123. if (fopen(name".inp", "r")) {
  124. freopen(name".inp", "r", stdin);
  125. freopen(name".out", "w", stdout);
  126. }
  127.  
  128. #define NAME "TASK"
  129. if (fopen(NAME".inp", "r")) {
  130. freopen(NAME".inp", "r", stdin);
  131. freopen(NAME".out", "w", stdout);
  132. }
  133.  
  134. solve();
  135. cerr << "Time elapsed: " << TIME << " s.\n";
  136. return 0;
  137. }
Success #stdin #stdout #stderr 0.01s 5296KB
stdin
[(i+10, j-5) | i <- [3..9], j <- [2,3,4]]
stdout
[(13,-3),(13,-2),(13,-1),(14,-3),(14,-2),(14,-1),(15,-3),(15,-2),(15,-1),(16,-3),(16,-2),(16,-1),(17,-3),(17,-2),(17,-1),(18,-3),(18,-2),(18,-1),(19,-3),(19,-2),(19,-1)]
stderr
Time elapsed: 0.006556 s.