Educational Codeforces Round 20 A

Description

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 ≤ 100, 0 ≤ k ≤ 106).

Output

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

Examples
input
2 1
output
1 0 
0 0
input
3 2
output
1 0 0 
0 1 0
0 0 0
input
2 5
output
-1
题意:问如何将二进制矩阵排成字典序最大(需要主对角线对称)
解法:当然是这种啦,如果发现还有剩余1就输出-1
1 1 1 1 1 1 1 1 1...
1 1
1 1
1 .
1 .
复制代码
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define ll long long
 4 const int maxn=654321;
 5 int x[200][200];
 6 int n;
 7 int num;
 8 int main()
 9 {
10     cin>>n>>num;
11     for(int i=1;num>0&&i<=n;i++)
12     {
13         x[i][i]=1;
14         num--;
15         for(int j=i+1;num>1&&j<=n;j++)
16         {
17             x[i][j]=x[j][i]=1;
18             num-=2;
19         }
20     }
21     if(num>0)
22     {
23         cout<<"-1"<<endl;
24         return 0;
25     }
26     for(int i=1;i<=n;i++)
27     {
28         for(int j=1;j<=n;j++)
29         {
30             cout<<x[i][j]<<" ";
31         }
32         cout<<endl;
33     }
34     return 0;
35 }
复制代码

 

posted @   樱花落舞  阅读(255)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示