問題一覧 > 通常問題

No.241 Attendance Numbers (1)

レベル : / AI推定難易度 : 750 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 166
作問者 : nmnmnmnmnmnmnm
お気に入りにしたユーザー ProblemId : 642 / 自分の提出
問題文最終更新日: 2026-06-25 04:00:06
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 114 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。