Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ┓┏┓┏┓┃
- ┛┗┛┗┛┃
- ┓┏┓┏┓┃
- ┛┗┛┗┛┃
- ┓┏┓┏┓┃\○/
- ┛┗┛┗┛┃ / /
- ┓┏┓┏┓┃ノ
- ┛┗┛┗┛┃
- ┓┏┓┏┓┃
- ┛┗┛┗┛┃
- ┓┏┓┏┓┃
- ┛┗┛┗┛┃
- ┓┏┓┏┓┃
- ┛┗┛┗┛┃
- ┓┏┓┏┓┃┓
- ┛┗┛┗┛┃┃
- MIPTCLASSICMIPTCLASSICMIPTCLASSICMIPTCLASSICMIPTCLASSICMIPTCLASSIC
- */
- // #define pragma
- #ifdef pragma
- #pragma GCC optimize("Ofast")
- #pragma GCC optimize("no-stack-protector")
- #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
- #pragma GCC optimize("unroll-loops")
- #pragma GCC diagnostic ignored "-Wunused-result"
- #endif // pragma
- #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 pb push_back
- #define x first
- #define y second
- #define int long long
- #define zero(two) memset(two, 0, sizeof(two))
- using namespace std;
- using namespace __gnu_pbds;
- typedef vector<int> vi;
- typedef vector<bool> vb;
- typedef pair<int, int> pii;
- typedef long double ld;
- typedef vector<vi> matrix;
- 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(10);
- #if 1
- freopen("input", "r", stdin);
- freopen("output", "w", stdout);
- #endif
- }
- const int INF = 1e9 + 7;
- signed main() {
- seriy();
- int n;
- cin >> n;
- matrix a(n);
- for(int i = 0; i < n; i++) {
- a[i].resize(n);
- for(int j = 0; j < i + 1; j++) {
- cin >> a[i][j];
- a[i][j] = ((a[i][j] == 0) ? -INF : a[i][j]);
- }
- }
- int cnt = 1;
- while(cnt--) {
- for(int i = 0; i < n; i++) {
- for(int j = 0; j <= i; j++) {
- if(a[i][j] != -INF) {
- // cerr << i << " " << j << '\n';
- for(int k = i + 1; k < n; k++) {
- int f = 0, cc = 0, sum = 0;
- for(int g = j; g <= j + (k - i); g++) {
- // cerr << g << " ";
- if(a[k][g] == -INF) {
- cc++;
- f = g;
- }
- else {
- sum += a[k][g];
- }
- }
- // cerr << '\n';
- // cerr << cc << '\n';
- if(cc == 1) {
- a[k][f] = (a[i][j] - sum) / 2;
- }
- }
- }
- else {
- if(i > 0 && j > 0 && a[i - 1][j - 1] != -INF && a[i][j - 1] != -INF) {
- a[i][j] = a[i - 1][j - 1] - a[i][j - 1];
- }
- else if(i > 0 && j < i && a[i - 1][j] != -INF && a[i][j + 1] != -INF) {
- // cerr << i << " " << j << '\n';
- a[i][j] = a[i - 1][j] - a[i][j + 1];
- }
- else if(i < n - 1 && a[i + 1][j] != -INF && a[i + 1][j + 1] != -INF) {
- a[i][j] = a[i + 1][j] + a[i + 1][j + 1];
- }
- }
- }
- }
- }
- // if(n > 1) a[0][0] = a[1][0] + a[1][1];
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < i + 1; j++) {
- assert(a[i][j] != -INF);
- cout << a[i][j] << " ";
- }
- cout << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement