-
Notifications
You must be signed in to change notification settings - Fork 0
/
A_Maximal_Binary_Matrix.cpp
42 lines (41 loc) · 998 Bytes
/
A_Maximal_Binary_Matrix.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
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
const long double EPS = 1e-14;
const int maxn = 100500;
const int mod = 1e9 + 7;
int a[110][110];
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, k;
cin >> n >> k;
if(k > n * n) return cout << -1 << '\n', 0;
int i = 0, j = 0;
for(; i < n && k; ++i){
for(j = 0 ; j < n && k; ++j){
if(a[i][j]) continue;
if(i == j){
a[i][j] = 1;
k--;
}else{
a[i][j] = a[j][i] = 1;
k -= 2;
}
if(k <= 1) break;
}
if(k <= 1) break;
}
if(k){
if(j >= i) i++;
if(i == n || a[i][i]) return cout << -1 << '\n', 0;
a[i][i] = 1;
}
for(int i = 0 ; i < n ; ++i){
for(int j = 0 ; j < n ; ++j)
cout << a[i][j] << ' ';
cout << '\n';
}
return 0;
}