Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main(){
- int a,b;
- scanf("%d%d",&a,&b);
- if(b > a){
- printf("-1\n");
- return 0;
- }
- if(b%2 == 0){
- for(int i=0;i<a;i++){
- for(int j=0;j<a;j++){
- if(b > 0 && i == j){
- printf("1 ");
- b--;
- }else printf("0 ");
- }
- printf("\n");
- }
- return 0;
- }
- int arr[a][a];
- for(int i=0;i<a;i++){
- for(int j=0;j<a;j++){
- arr[i][j] = 0;
- }
- }
- int j = 0;
- arr[0][0] = 1;
- b--;
- for(int i=0;i<(b/2)+1;i++){
- arr[i][j] = 1;
- arr[j][i] = 1;
- if(i > a)j++;
- }
- for(int i=0;i<a;i++){
- for(int j=0;j<a;j++){
- if(arr[i][j] == 1)printf("1 ");
- else printf("0 ");
- }
- printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement