No.2263 Perms
タグ : / 解いたユーザー数 59
作問者 :
milkcoffee
/ テスター :
とりゐ
sotanishy
Problem Statement
There are $M$ permutations $(P_1,P_2,\cdots,P_N)$ of $(1,2,\cdots,N)$. The number of permutations with $P_i = j$ was $A_{i,j}$.
Does there exist a tuple of $M$ permutations satisfying the condition?
If one exists, find such a tuple of permutations.
Input
$N$ $M$
$A_{1,1}$ $\cdots$ $A_{1,N}$
$\vdots$
$A_{N,1}$ $\cdots$ $A_{N,N}$
- $2 \leq N,M \leq 50$
- $0 \leq A_{i,j} \leq M$ $(1 \leq i,j \leq N)$
- All inputs are integers.
Output
If no tuple of permutations satisfying the condition exists, print -1.
If one exists, print $M$ lines in total, with the $i$-th permutation on the $i$-th line.
If there are multiple answers, you may print any of them.
Sample
Sample 1
Input
3 2 0 1 1 0 1 1 2 0 0
Output
2 3 1 3 2 1
One possibility is that the $1$st permutation is $(2,3,1)$ and the $2$nd permutation is $(3,2,1)$.
The $2$ permutations may be printed in any order.
Sample 2
Input
2 5 2 3 2 3
Output
-1
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。