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  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.
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.
输入格式
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.
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.
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++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted