

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
人の選手がテニスの大会に参加します。彼らを選手 、選手 、、選手 と呼びます。
大会は総当たり戦で、合計 試合が行われます。 これらの試合の日程を、以下の条件をすべて満たすように決めることは可能でしょうか。可能である場合、必要な最小の日数も求めてください。
- 各選手は一日に最大で一試合を行う。
- 各選手 は、選手 とこの順に一度ずつ試合を行う。
制約
- はすべて異なる。
入力
入力は以下の形式で標準入力から与えられる。
出力
条件をすべて満たすように全試合の日程を決めることが可能なら必要な最小の日数を、不可能なら -1
を出力せよ。
入力例 1Copy
3 2 3 1 3 1 2
出力例 1Copy
3
日間で次のように試合を行えばすべての条件を満たせます。
- 日目: 選手 対 選手
- 日目: 選手 対 選手
- 日目: 選手 対 選手
これが必要な最小日数です。
入力例 2Copy
4 2 3 4 1 3 4 4 1 2 3 1 2
出力例 2Copy
4
日間で次のように試合を行えばすべての条件を満たせます。
- 日目: 選手 対 選手 、選手 対 選手
- 日目: 選手 対 選手
- 日目: 選手 対 選手 、選手 対 選手
- 日目: 選手 対 選手
これが必要な最小日数です。
入力例 3Copy
3 2 3 3 1 1 2
出力例 3Copy
-1
どのような日程で試合を行っても何らかの条件に違反します。
Score : points
Problem Statement
players will participate in a tennis tournament. We will call them Player , Player , , Player .
The tournament is round-robin format, and there will be matches in total. Is it possible to schedule these matches so that all of the following conditions are satisfied? If the answer is yes, also find the minimum number of days required.
- Each player plays at most one matches in a day.
- Each player plays one match against Player in this order.
Constraints
- are all different.
Input
Input is given from Standard Input in the following format:
Output
If it is possible to schedule all the matches so that all of the conditions are satisfied, print the minimum number of days required; if it is impossible, print -1
.
Sample Input 1Copy
3 2 3 1 3 1 2
Sample Output 1Copy
3
All the conditions can be satisfied if the matches are scheduled for three days as follows:
- Day : Player vs Player
- Day : Player vs Player
- Day : Player vs Player
This is the minimum number of days required.
Sample Input 2Copy
4 2 3 4 1 3 4 4 1 2 3 1 2
Sample Output 2Copy
4
All the conditions can be satisfied if the matches are scheduled for four days as follows:
- Day : Player vs Player , Player vs Player
- Day : Player vs Player
- Day : Player vs Player , Player vs Player
- Day : Player vs Player
This is the minimum number of days required.
Sample Input 3Copy
3 2 3 3 1 1 2
Sample Output 3Copy
-1
Any scheduling of the matches violates some condition.