結果

問題 No.241 出席番号(1)
ユーザー urunea
提出日時 2025-05-01 01:55:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 957 bytes
コンパイル時間 477 ms
コンパイル使用メモリ 82,540 KB
実行使用メモリ 54,264 KB
最終ジャッジ日時 2025-05-01 01:55:27
合計ジャッジ時間 3,546 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
mem=[]
for i in range(N):
    a=int(input())
    mem.append([a, i])

if N == 1:
    if a == 0:
        print(-1)
    else:
        print(0)
    exit()

mem=sorted(mem, key=lambda x: x[0])
res=[N-i-1 for i in range(N)]

for i in range(N):
    if res[i] == mem[i][0]:
        j = i - 1
        found=False
        while 0 <= j:
            if mem[j][0] == mem[i][0]:
                j -= 1
            else:
                res[i], res[j] = res[j], res[i]
                found=True
                break
        
        if found:
            break
        j = i + 1
        while j < N:
            if mem[j][0] == mem[i][0]:
                j += 1
            else:
                res[i], res[j] = res[j], res[i]
                found=True
                break

        if found:
            break
        else:
            print(-1)
            exit()

ans=[-1]*N
for i in range(N):
    ans[mem[i][1]] = res[i]

for i in ans:
    print(i)
0