No.241 Attendance Numbers (1)
タグ : / 解いたユーザー数 166
作問者 :
nmnmnmnmnmnmnm
Problem Statement
There is a class with $N$ students. The students are named $S_0$ through $S_{N-1}$.
You want to assign each student an attendance number from $0$ to $N-1$.
However, each student has one number they dislike and do not want as their attendance number.
Assign the attendance numbers so that no student receives the number they dislike.
Note: test2.txt may be a corner case. If you do not get AC, read the constraints carefully.
Input
$N$
$A_0$
$A_1$
$\vdots$
$A_{N-1}$
The first line gives the number of students $N$. $1 \le N \le 50$.
The following $N$ lines give the number $A_i$ that $S_i$ dislikes. $0 \le A_i \le 49$.
Output
Output the attendance numbers of $S_0$ through $S_{N-1}$ in order, over $N$ lines.
Attendance numbers must not overlap, so each number from $0$ to $N-1$ must appear exactly $1$ time.
There are multiple correct answers; output any $1$ of them.
If it is impossible to assign the attendance numbers, output -1 on $1$ line.
Print a newline at the end.
Sample
Sample 1
Input
3 0 1 2
Output
2 0 1
$S_0$ dislikes $0$.
$S_1$ dislikes $1$.
$S_2$ dislikes $2$.
Therefore, $2$ is assigned to $S_0$, $0$ to $S_1$, and $1$ to $S_2$.
Sample 2
Input
4 3 3 3 3
Output
-1
Attendance number 3 cannot be assigned to anyone.
Therefore, assigning the attendance numbers is impossible.
Sample 3
Input
5 1 1 1 0 1
Output
4 2 0 1 3
$S_3$ must be assigned attendance number 1.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。