목차

행렬만들기

ps
링크acmicpc.net/…
출처BOJ
문제 번호1960
문제명행렬만들기
레벨골드 3
분류

그리디

시간복잡도O(n^2)
인풋사이즈n<=500
사용한 언어Python
제출기록30864KB / 72ms
최고기록72ms
해결날짜2022/02/05

풀이

코드

"""Solution code for "BOJ 1960. 행렬만들기".

- Problem link: https://www.acmicpc.net/problem/1960
- Solution link: http://www.teferi.net/ps/problems/boj/1960

Tags: [Greedy]
"""


def main():
    n = int(input())
    count_by_row = [int(x) for x in input().split()]
    count_by_col = [int(x) for x in input().split()]

    answer = []
    sorted_cols = list(range(n))
    for count in count_by_row:
        answer_row = ['0'] * n
        sorted_cols.sort(reverse=True, key=count_by_col.__getitem__)
        for col in sorted_cols[:count]:
            count_by_col[col] -= 1
            answer_row[col] = '1'
        answer.append(''.join(answer_row))

    if all(x == 0 for x in count_by_col):
        print('1')
        print('\n'.join(answer))
    else:
        print('-1')


if __name__ == '__main__':
    main()