Advertisement
GerONSo

J спбгу

Jan 16th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. /*
  2. ┓┏┓┏┓┃
  3. ┛┗┛┗┛┃
  4. ┓┏┓┏┓┃
  5. ┛┗┛┗┛┃
  6. ┓┏┓┏┓┃\○/
  7. ┛┗┛┗┛┃ / /
  8. ┓┏┓┏┓┃ノ
  9. ┛┗┛┗┛┃
  10. ┓┏┓┏┓┃
  11. ┛┗┛┗┛┃
  12. ┓┏┓┏┓┃
  13. ┛┗┛┗┛┃
  14. ┓┏┓┏┓┃
  15. ┛┗┛┗┛┃
  16. ┓┏┓┏┓┃┓
  17. ┛┗┛┗┛┃┃
  18. MIPTCLASSICMIPTCLASSICMIPTCLASSICMIPTCLASSICMIPTCLASSICMIPTCLASSIC
  19. */
  20.  
  21. // #define pragma
  22.  
  23. #ifdef pragma
  24. #pragma GCC optimize("Ofast")
  25. #pragma GCC optimize("no-stack-protector")
  26. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  27. #pragma GCC optimize("unroll-loops")
  28. #pragma GCC diagnostic ignored "-Wunused-result"
  29. #endif // pragma
  30.  
  31. #include<bits/stdc++.h>
  32. #include <ext/pb_ds/assoc_container.hpp>
  33. #include <ext/pb_ds/tree_policy.hpp>
  34.  
  35. #define ll long long
  36. #define all(x) begin(x), end(x)
  37. #define pb push_back
  38. #define x first
  39. #define y second
  40. #define int long long
  41. #define zero(two) memset(two, 0, sizeof(two))
  42.  
  43. using namespace std;
  44. using namespace __gnu_pbds;
  45.  
  46.  
  47. typedef vector<int> vi;
  48. typedef vector<bool> vb;
  49. typedef pair<int, int> pii;
  50. typedef long double ld;
  51. typedef vector<vi> matrix;
  52. template<typename T>
  53. using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  54.  
  55. const ld PI = atan2(0, -1);
  56.  
  57. void seriy() {
  58. ios::sync_with_stdio(0);
  59. cin.tie(0);
  60. cout.tie(0);
  61. cout << fixed << setprecision(10);
  62. #if 1
  63. freopen("input", "r", stdin);
  64. freopen("output", "w", stdout);
  65. #endif
  66. }
  67.  
  68. const int INF = 1e9 + 7;
  69.  
  70. signed main() {
  71. seriy();
  72. int n;
  73. cin >> n;
  74. matrix a(n);
  75. for(int i = 0; i < n; i++) {
  76. a[i].resize(n);
  77. for(int j = 0; j < i + 1; j++) {
  78. cin >> a[i][j];
  79. a[i][j] = ((a[i][j] == 0) ? -INF : a[i][j]);
  80. }
  81. }
  82. int cnt = 1;
  83. while(cnt--) {
  84. for(int i = 0; i < n; i++) {
  85. for(int j = 0; j <= i; j++) {
  86. if(a[i][j] != -INF) {
  87. // cerr << i << " " << j << '\n';
  88. for(int k = i + 1; k < n; k++) {
  89. int f = 0, cc = 0, sum = 0;
  90. for(int g = j; g <= j + (k - i); g++) {
  91. // cerr << g << " ";
  92. if(a[k][g] == -INF) {
  93. cc++;
  94. f = g;
  95. }
  96. else {
  97. sum += a[k][g];
  98. }
  99. }
  100. // cerr << '\n';
  101. // cerr << cc << '\n';
  102. if(cc == 1) {
  103. a[k][f] = (a[i][j] - sum) / 2;
  104. }
  105. }
  106. }
  107. else {
  108. if(i > 0 && j > 0 && a[i - 1][j - 1] != -INF && a[i][j - 1] != -INF) {
  109. a[i][j] = a[i - 1][j - 1] - a[i][j - 1];
  110. }
  111. else if(i > 0 && j < i && a[i - 1][j] != -INF && a[i][j + 1] != -INF) {
  112. // cerr << i << " " << j << '\n';
  113. a[i][j] = a[i - 1][j] - a[i][j + 1];
  114. }
  115. else if(i < n - 1 && a[i + 1][j] != -INF && a[i + 1][j + 1] != -INF) {
  116. a[i][j] = a[i + 1][j] + a[i + 1][j + 1];
  117. }
  118. }
  119. }
  120. }
  121. }
  122. // if(n > 1) a[0][0] = a[1][0] + a[1][1];
  123. for(int i = 0; i < n; i++) {
  124. for(int j = 0; j < i + 1; j++) {
  125. assert(a[i][j] != -INF);
  126. cout << a[i][j] << " ";
  127. }
  128. cout << '\n';
  129. }
  130. return 0;
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement