CF850D.Tournament Construction
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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
for all 1 ≤ k < n and
.
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.
伊万正在阅读一本关于竞赛图的书。他了解到,竞赛图是一种有向图,其任意两个顶点之间恰好存在一条有向边。一个顶点的得分是指从该顶点出发的有向边的数量。
昨天,伊万学习了兰道准则(Landau’s criterion):存在一个得分序列为 d1≤d2≤⋯≤dn 的竞赛图,当且仅当对所有 1≤k<n 满足
,
且满足
。
现在,伊万想解决如下问题:给定一个数集 S={a1,a2,…,am},是否存在一个竞赛图,其得分集合(即所有不同得分构成的集合)恰好为 S?换言之,是否存在某个竞赛图,其得分序列为 d1,d2,…,dn,使得将该序列中重复的得分去除后,所得集合恰好为 {a1,a2,…,am}?
请找出满足条件的顶点数最少的竞赛图。
输入格式
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.
第一行包含一个整数 m(1≤m≤31)。
下一行包含 m 个互不相同的整数 a1,a2,...,am(0≤ai≤30)——集合 S 的元素。保证集合中所有元素互不相同。
输出格式
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.
如果不存在这样的竞赛图,请输出字符串 \=((不带引号)。
否则,输出一个整数 n —— 竞赛图的顶点数。
然后输出 n 行,每行 n 个字符 —— 竞赛图的邻接矩阵。第 i 行第 j 列的元素应为 1,当且仅当从第 i 个顶点指向第 j 个顶点存在一条有向边;否则为 0。主对角线上的元素必须全为 0。
输入输出样例
输入#1
2 1 2
输出#1
4 0011 1001 0100 0010
输入#2
2 0 3
输出#2
6 000111 100011 110001 011001 001101 000000
输入解题思路,AI测评打分。不知道怎么写?