题库练习 Tournament Construction
← 上一题 下一题 →

A11076 | Tournament Construction

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

Ivan is reading a book about tournaments. He knows that a tournament is an oriented graph with exactly one oriented edge between each pair of vertices. The score of a vertex is the number of edges going outside this vertex.

Yesterday Ivan learned Landau's criterion: there is tournament with scores $d_{1}<=d_{2}<=...<=d_{n}$ if and only if ![](/uploads/luogu/CF850D/4fe680476592e82ee231e53c258b2a4afe965574_1bc187e85dce.png) for all $1<=k<n$ and ![](/uploads/acgo/image/9579680b2e0ee805_d39454ea8d88.jpeg).

Now, Ivan wanna solve following problem: given a set of numbers $S={a_{1},a_{2},...,a_{m}}$ , is there a tournament with given set of scores? I.e. is there tournament with sequence of scores $d_{1},d_{2},...,d_{n}$ such that if we remove duplicates in scores, we obtain the required set ${a_{1},a_{2},...,a_{m}}$ ?

Find a tournament with minimum possible number of vertices.

输入格式

The first line contains a single integer $m$ ( $1<=m<=31$ ).

The next line contains $m$ distinct integers $a_{1},a_{2},...,a_{m}$ ( $0<=a_{i}<=30$ ) — elements of the set $S$ . It is guaranteed that all elements of the set are distinct.

输出格式

If there are no such tournaments, print string "=(" (without quotes).

Otherwise, print an integer $n$ — the number of vertices in the tournament.

Then print $n$ lines with $n$ characters — matrix of the tournament. The $j$ -th element in the $i$ -th row should be $1$ if the edge between the $i$ -th and the $j$ -th vertices is oriented towards the $j$ -th vertex, and $0$ otherwise. The main diagonal should contain only zeros.

输入输出样例

输入 #1
2
1 2
输出 #1
4
0011
1001
0100
0010
输入 #2
2
0 3
输出 #2
6
000111
100011
110001
011001
001101
000000
C++ 编辑器
输入
输出