結果

問題 No.241 出席番号(1)
ユーザー rpy3cpprpy3cpp
提出日時 2015-07-10 23:12:15
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 813 bytes
コンパイル時間 75 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-07-08 02:09:03
合計ジャッジ時間 2,263 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26 WA * 3
権限があれば一括ダウンロードができます

ソースコード

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:
        return [-1]
    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