영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)
Problem
Lieutenant's Lotto is a game whose rules are as follows: You are given a positive integer N and a list of numbers p_1, p_2, …, p_N such that every integer from 1 to N is present in the list (i.e. it is a permutation). The objective is to find an N × N grid of zeroes and ones, such that
- No two rows are identical, and
- The ith row is equal to the p_ith column, for every 1 ≤ i ≤ N.
Your task is to construct such a grid, if possible.
Input
The first line contains one integer N (2 ≤ N ≤ 1000).
The second line contains N integers p_1, p_2, …, p_N (1 ≤ p_i ≤ N). Every integer from 1 to N is present in this list of numbers.
Output
If a valid grid exists, print one line with “YES”, followed by N lines, each containing a string of length N. These N lines constitute the grid.
If a valid grid does not exist, print “NO”.
Scoring
Your solution will be tested on a set of test groups. To earn points for a group, you must pass all test cases in that group.
| Group | Points | Constraints |
|---|---|---|
| 1 | 11 | p_i = i for all 1 ≤ i ≤ N. |
| 2 | 12 | N ≤ 5 |
| 3 | 15 | p_i = i+1 for every 1 ≤ i ≤ N-1, and p_N = 1. |
| 4 | 24 | p_{p_i} ≠ i for all 1 ≤ i ≤ N. |
| 5 | 38 | No additional constraints. |
Explanation of Samples
In the first sample, the first row and the second column are both 1100, which means that they are equal. The other rows also correspond to their respective columns.
In the second sample, the only way to make the rows equal to their corresponding column is by having the grid be all zeros or all ones. But then the rows would not be different.
예제
예제 1
4 2 3 1 4
YES 1100 0110 1010 0001
예제 2
2 2 1
NO