結果

問題 No.241 出席番号(1)
ユーザー rpy3cpprpy3cpp
提出日時 2015-07-10 23:20:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 877 bytes
コンパイル時間 557 ms
コンパイル使用メモリ 10,796 KB
実行使用メモリ 8,708 KB
最終ジャッジ日時 2023-08-20 17:45:49
合計ジャッジ時間 2,529 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,608 KB
testcase_01 AC 24 ms
8,560 KB
testcase_02 AC 20 ms
8,604 KB
testcase_03 AC 19 ms
8,688 KB
testcase_04 AC 19 ms
8,600 KB
testcase_05 AC 19 ms
8,664 KB
testcase_06 AC 20 ms
8,640 KB
testcase_07 AC 19 ms
8,580 KB
testcase_08 AC 20 ms
8,504 KB
testcase_09 AC 19 ms
8,584 KB
testcase_10 AC 19 ms
8,692 KB
testcase_11 AC 19 ms
8,636 KB
testcase_12 AC 19 ms
8,504 KB
testcase_13 AC 20 ms
8,560 KB
testcase_14 AC 20 ms
8,664 KB
testcase_15 AC 20 ms
8,696 KB
testcase_16 AC 19 ms
8,560 KB
testcase_17 AC 19 ms
8,568 KB
testcase_18 AC 20 ms
8,708 KB
testcase_19 AC 19 ms
8,660 KB
testcase_20 AC 19 ms
8,652 KB
testcase_21 AC 19 ms
8,692 KB
testcase_22 AC 19 ms
8,576 KB
testcase_23 AC 20 ms
8,664 KB
testcase_24 AC 20 ms
8,616 KB
testcase_25 AC 21 ms
8,604 KB
testcase_26 AC 20 ms
8,648 KB
testcase_27 AC 20 ms
8,540 KB
testcase_28 AC 20 ms
8,660 KB
testcase_29 AC 20 ms
8,612 KB
testcase_30 AC 19 ms
8,616 KB
testcase_31 AC 19 ms
8,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections

def read_data():
    N = int(input())
    As = [int(input()) for i in range(N)]
    return N, As

def solve(N, As):
    if N == 1:
        if As[0] == 0:
            return [-1]
        else:
            return [0]
    result = [-1] * N
    freq = collections.Counter([a for a in As if a < N])
    free = [i for i in range(N) if i not in freq]
    most_com = freq.most_common()
    poss = [pos for pos, count in most_com] + free
    priority = [(0 if a not in freq else freq[a], i, a) for i, a in enumerate(As)]
    priority.sort()
    for pos in poss:
        idx = len(priority) - 1
        while priority[idx][2] == pos:
            idx -= 1
            if idx < 0:
                return [-1]
        result[priority[idx][1]] = pos
        del priority[idx]
    return result

N, As = read_data()
answer = solve(N, As)
for ans in answer:
    print(ans)
0