-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy path1517C.cpp
More file actions
115 lines (98 loc) · 2.14 KB
/
1517C.cpp
File metadata and controls
115 lines (98 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Problem link: https://codeforces.com/problemset/problem/1517/C
// Author: Akshat
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define vvll vector<vll>
#define vld vector<ld>
#define pll pair<ll, ll>
#define ppll pair<ll, pll>
#define pld pair<ld, ld>
#define vpll vector<pll>
#define vpld vector<pld>
#define all(X) X.begin(), X.end()
#define endl "\n"
#define sz(x) ((ll)((x).size()))
vll emptyVector;
const ll MAX = 1e5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
ll binaryExpo(ll x, ll n) {
if (n == 0)
return 1;
if (n % 2 == 0)
return binaryExpo((x * x) % MOD, n / 2);
return (x * binaryExpo((x * x) % MOD, n / 2)) % MOD;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}
/*------------------------------------------- CODE STARTS FROM HERE ------------------------------------------*/
vvll ans;
bool can_go_left(int i, int j) {
if (j - 1 < 0) {
return false;
}
if (ans[i][j - 1] != 0) {
return false;
}
return true;
}
void dfs(int i, int j, int val, int place_val) {
ans[i][j] = place_val;
if (val <= 0) {
return;
}
if (can_go_left(i, j)) {
dfs(i, j - 1, val - 1, place_val);
return;
}
dfs(i + 1, j, val - 1, place_val);
}
void solve() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
ans.pb(emptyVector);
for (int j = 0; j < n; j++) {
ans[i].pb(0);
}
ll x;
cin >> x;
ans[i][i] = x;
}
for (int i = 0; i < n; i++) {
dfs(i, i, ans[i][i] - 1, ans[i][i]);
}
for (auto v : ans) {
for (auto x : v) {
if (x == 0) {
break;
}
cout << x << " ";
}
cout << endl;
}
}
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// int t;
// cin >> t;
// while (t--) {
solve();
// }
return 0;
}