結果

問題 No.241 出席番号(1)
ユーザー しらっ亭しらっ亭
提出日時 2015-09-26 03:25:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 807 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 10,816 KB
実行使用メモリ 12,640 KB
最終ジャッジ日時 2023-09-26 16:27:28
合計ジャッジ時間 6,099 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
12,364 KB
testcase_01 AC 18 ms
7,944 KB
testcase_02 AC 18 ms
7,856 KB
testcase_03 AC 16 ms
7,784 KB
testcase_04 AC 16 ms
7,788 KB
testcase_05 AC 16 ms
7,864 KB
testcase_06 AC 16 ms
7,780 KB
testcase_07 AC 17 ms
7,784 KB
testcase_08 AC 16 ms
7,776 KB
testcase_09 AC 17 ms
7,776 KB
testcase_10 AC 16 ms
7,812 KB
testcase_11 AC 17 ms
7,780 KB
testcase_12 AC 17 ms
7,944 KB
testcase_13 AC 17 ms
7,820 KB
testcase_14 AC 16 ms
8,296 KB
testcase_15 AC 17 ms
8,332 KB
testcase_16 AC 16 ms
7,780 KB
testcase_17 AC 16 ms
7,868 KB
testcase_18 AC 16 ms
7,964 KB
testcase_19 AC 16 ms
7,832 KB
testcase_20 AC 16 ms
7,904 KB
testcase_21 AC 16 ms
7,864 KB
testcase_22 AC 16 ms
7,868 KB
testcase_23 AC 16 ms
7,816 KB
testcase_24 AC 16 ms
8,224 KB
testcase_25 TLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve():
    N = int(input())

    C = [[] for _ in range(N)]

    for i in range(N):
        a = int(input())
        for j in range(N):
            if j != a:
                C[j].append(i)

    for j in range(N):
        if len(C[j]) == 0:
            print(-1)
            return

    ans = [0] * N
    used = set()
    # ans[i] は i 番を振った人

    def dfs(j):
        if j == N:
            return True
        for k in C[j]:
            if k not in used:
                ans[j] = k
                used.add(k)
                if dfs(j + 1):
                    return True
                used.remove(k)

    if dfs(0):
        l = list(zip(ans, range(N)))
        l.sort()
        for i, j in l:
            print(j)
    else:
        print(-1)


if __name__ == '__main__':
    solve()
0