803A - Maximal Binary Matrix - CodeForces Solution


constructive algorithms *1400

Please click on ads to support us..

Python Code:

n,k=map(int,input().split())
if k>n**2:
    print(-1)
else:
    m=n
    while (k-2*n+1)>=0 and k>0 and n>0:
        k-=2*n-1
        n-=1
    matrix=[[0 for _ in range(n)] for _ in range(n)]
    if k%2==1:
        x=k//2+1
        for _ in range(x):
            matrix[0][_],matrix[_][0]=1,1
    else:
        x=k//2
        if n>1 and k>0:
            matrix[1][1]=1
        for _ in range(x):
            matrix[0][_],matrix[_][0]=1,1
    Matrix=[[1]*m]*(m-n)+[[1]*(m-n)+matrix[_] for _ in range(n)]
    for i in range(m):
        for j in Matrix[i]:
            print(j,end=' ')
        print('')


Comments

Submit
0 Comments
More Questions

834A - The Useless Toy
1407D - Discrete Centrifugal Jumps
1095B - Array Stabilization
291B - Command Line Arguments
1174B - Ehab Is an Odd Person
624B - Making a String
1064C - Oh Those Palindromes
1471A - Strange Partition
1746A - Maxmina
1746B - Rebellion
66C - Petya and File System
1746C - Permutation Operations
1199B - Water Lily
570B - Simple Game
599C - Day at the Beach
862A - Mahmoud and Ehab and the MEX
1525A - Potion-making
1744D - Divisibility by 2n
1744A - Number Replacement
1744C - Traffic Light
1744B - Even-Odd Increments
637B - Chat Order
546C - Soldier and Cards
18D - Seller Bob
842B - Gleb And Pizza
1746D - Paths on the Tree
1651E - Sum of Matchings
19A - World Football Cup
630P - Area of a Star
1030C - Vasya and Golden Ticket