# Educational Codeforces Round 20 A. Maximal Binary Matrix

## 1.题目链接

http://codeforces.com/contest/803/problem/A

## 2.题面

A. Maximal Binary Matrix
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given matrix with n rows and n columns filled with zeroes. You should put k ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.

One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one.

If there exists no such matrix then output -1.

Input

The first line consists of two numbers n and k (1 ≤ n ≤ 1000 ≤ k ≤ 106).

Output

If the answer exists then output resulting matrix. Otherwise output -1.

Examples
input
Copy
2 1

output
Copy
1 0
0 0

input
Copy
3 2

output
Copy
1 0 0
0 1 0
0 0 0

input
Copy
2 5

output
Copy
-1

## 5.代码实现

#include<iostream>
#include<math.h>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include <time.h>
#include<string.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 105;
const int Mod=1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e=2.718281828459045235360287471352662;
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
int a[maxn][maxn];
int main()
{
ios::sync_with_stdio(false);
int n,k;
cin>>n>>k;
if(k>n*n)
{
cout<<-1<<endl;
return 0;
}
for(int i=0;i<n;i++)
{
if(k==0)
break;
for(int j=0;j<n;j++)
{
if(k==0)
break;
if(a[i][j]==0)
{
if(i==j)
{
a[i][j]=1;
k--;
}
else
{
if(k>=2)
{
a[i][j]=1;
a[j][i]=1;
k-=2;
}
}
}
if(k==0)
break;
}
if(k==0)
break;
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
//cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}


## 6.反思

• 本文已收录于以下专栏：

举报原因： 您举报文章：Educational Codeforces Round 20 A. Maximal Binary Matrix 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)