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()