結果

問題 No.2740 Old Maid
ユーザー D M
提出日時 2025-04-03 15:21:34
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 550 bytes
コンパイル時間 423 ms
コンパイル使用メモリ 82,744 KB
実行使用メモリ 67,712 KB
最終ジャッジ日時 2025-04-03 15:21:44
合計ジャッジ時間 9,412 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 3
other RE * 62
権限があれば一括ダウンロードができます

ソースコード

diff #

from sortedcontainers import SortedSet
from collections import defaultdict
n=int(input())
P=list(map(int,input().split()))
S=SortedSet([])
for i in range(1,n+1):
    S.add(i)
D=defaultdict(lambda: [-1, -1])
for i in range(n):
    if i>0:
        D[P[i]][0]=P[i-1]
    if i<n-1:
        D[P[i]][1]=P[i+1]
ans=[]
while len(S)>0:
    now=S[0]
    if D[now][1]==-1:
        now=S[1]
    ans.append(now)
    ans.append(D[now][1])
    S.remove(now)
    S.remove(D[now][1])
    D[D[now][0]][1]=D[D[now][1]][1]
    D[D[D[now][1]][1]][0]=D[now][0]
print(*ans)
0