結果
| 問題 |
No.241 出席番号(1)
|
| ユーザー |
はむ吉🐹
|
| 提出日時 | 2016-04-03 20:48:18 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 34 ms / 2,000 ms |
| コード長 | 996 bytes |
| コンパイル時間 | 107 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 11,392 KB |
| 最終ジャッジ日時 | 2024-11-30 21:35:34 |
| 合計ジャッジ時間 | 2,283 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
ソースコード
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import array
import random
MAX_TRIAL = 10 ** 6
class NoSolutionError(Exception):
pass
def is_valid(candidate, bad_numbers):
return all(c != b for c, b in zip(candidate, bad_numbers))
def solve(num_of_pupils, bad_numbers, trial=MAX_TRIAL):
candidate = array.array("B", range(num_of_pupils))
if len(set(bad_numbers)) == 1 and bad_numbers[0] in candidate:
raise NoSolutionError
for _ in range(trial):
random.shuffle(candidate)
if is_valid(candidate, bad_numbers):
return candidate
else:
raise NoSolutionError
def main():
num_of_pupils = int(input())
bad_numbers = array.array("B", (int(input())
for _ in range(num_of_pupils)))
try:
answer = solve(num_of_pupils, bad_numbers)
except NoSolutionError:
print(-1)
else:
for x in answer:
print(x)
if __name__ == '__main__':
main()
はむ吉🐹