結果

問題 No.241 出席番号(1)
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-04-03 20:48:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 996 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 10,788 KB
実行使用メモリ 9,192 KB
最終ジャッジ日時 2023-08-20 17:54:28
合計ジャッジ時間 2,187 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
9,104 KB
testcase_01 AC 17 ms
9,164 KB
testcase_02 AC 17 ms
9,052 KB
testcase_03 AC 17 ms
9,084 KB
testcase_04 AC 17 ms
9,148 KB
testcase_05 AC 19 ms
9,108 KB
testcase_06 AC 20 ms
9,052 KB
testcase_07 AC 19 ms
9,020 KB
testcase_08 AC 17 ms
9,160 KB
testcase_09 AC 17 ms
9,020 KB
testcase_10 AC 17 ms
8,988 KB
testcase_11 AC 16 ms
8,984 KB
testcase_12 AC 17 ms
9,108 KB
testcase_13 AC 18 ms
9,020 KB
testcase_14 AC 18 ms
9,168 KB
testcase_15 AC 17 ms
9,056 KB
testcase_16 AC 16 ms
9,192 KB
testcase_17 AC 16 ms
9,092 KB
testcase_18 AC 17 ms
9,040 KB
testcase_19 AC 17 ms
9,160 KB
testcase_20 AC 18 ms
9,080 KB
testcase_21 AC 17 ms
9,080 KB
testcase_22 AC 17 ms
9,108 KB
testcase_23 AC 17 ms
8,984 KB
testcase_24 AC 18 ms
9,024 KB
testcase_25 AC 20 ms
9,040 KB
testcase_26 AC 17 ms
9,160 KB
testcase_27 AC 17 ms
9,052 KB
testcase_28 AC 16 ms
9,108 KB
testcase_29 AC 18 ms
9,044 KB
testcase_30 AC 17 ms
9,056 KB
testcase_31 AC 17 ms
9,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/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()
0