-
Notifications
You must be signed in to change notification settings - Fork 14
/
2084.cpp
50 lines (49 loc) · 888 Bytes
/
2084.cpp
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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define X first
#define Y second
#define pb push_back
int a[2003][2003];
int main(void){
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
pair<int,int> v[n];
int tot = 0;
for(int i = 0; i < n; i++){
cin >> v[i].X;
tot += v[i].X;
v[i].Y = i;
}
if(tot%2==1){
cout << -1;
return 0;
}
while(true){
sort(v,v+n,greater<pair<int,int> >() );
if(v[0].X == 0) break;
int cnt = v[0].X;
v[0].X = 0;
int i = 1;
while(cnt){
if(i==n){
cout << -1;
return 0;
}
if(a[v[0].Y][v[i].Y]){
i++;
continue;
}
a[v[0].Y][v[i].Y] = a[v[i].Y][v[0].Y] = 1;
v[i].X--;
i++;
cnt--;
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++) cout << a[i][j] << ' ';
cout << '\n';
}
}