시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 256 MB138550.000%

문제

Dr. Who is organising a banquet, and will be inviting several guests. A guest is happy, if he can chat with a fixed number of other guests. We assume that guests cannot talk to themselves. Help Dr. Who make all his guests happy, if possible, by organising chats between guests.

입력

The program input is from a text file. The file contains several data sets, and each data set is encoded on a line from the file. A data set consists of n≤10000 positive integers a1, a2, … an, separated by single whitespaces. The last integer an is immediately followed by the newline character. Each number ai, with 1≤i≤n is the number of chat partners guest i would like to have. We assume that ai≤1000 for all 1≤i≤n. The last data set is followed by the end of file.

출력

If all guests can be made happy, the program output consists of a n×n matrix m, where m[i][j]=m[j][i]=1 if guests i and j chat, and m[i][j]=m[j][i]=0, otherwise. The matrix will be represented at standard output, as follows: each value m[i][j] from a row will be followed by one whitespace (including the last value from the row). Each row will be separated by the newline character. If it is not possible for all guests to be happy, then the program output is the message “fail”. The matrix and the message are allways followed by an empty line.

예제 입력 1

3 3 1 1
4 4 3 3 2 2 2
3 3 1 1
2 2 2 2

예제 출력 1

fail

0 1 1 0 1 0 1
1 0 0 1 1 0 1
1 0 0 1 0 1 0
0 1 1 0 0 1 0
1 1 0 0 0 0 0
0 0 1 1 0 0 0
1 1 0 0 0 0 0

fail

0 1 1 0
1 0 0 1
1 0 0 1
0 1 1 0

출처

ICPC > Regionals > Europe > Southeastern European Regional Contest > SEERC 2012 A번

  • 스페셜 저지를 만든 사람: ntopia