結果

問題 No.2740 Old Maid
ユーザー detteiuudetteiuu
提出日時 2024-04-24 22:05:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 600 ms / 2,000 ms
コード長 754 bytes
コンパイル時間 545 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 148,896 KB
最終ジャッジ日時 2024-04-24 22:06:18
合計ジャッジ時間 22,635 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 398 ms
148,256 KB
testcase_01 AC 439 ms
148,252 KB
testcase_02 AC 393 ms
148,564 KB
testcase_03 AC 409 ms
148,636 KB
testcase_04 AC 424 ms
148,384 KB
testcase_05 AC 408 ms
148,392 KB
testcase_06 AC 396 ms
148,264 KB
testcase_07 AC 430 ms
148,260 KB
testcase_08 AC 395 ms
148,260 KB
testcase_09 AC 403 ms
148,508 KB
testcase_10 AC 396 ms
148,896 KB
testcase_11 AC 368 ms
148,168 KB
testcase_12 AC 440 ms
124,288 KB
testcase_13 AC 450 ms
121,088 KB
testcase_14 AC 178 ms
88,320 KB
testcase_15 AC 201 ms
94,720 KB
testcase_16 AC 364 ms
128,000 KB
testcase_17 AC 173 ms
86,504 KB
testcase_18 AC 430 ms
124,800 KB
testcase_19 AC 237 ms
103,680 KB
testcase_20 AC 528 ms
127,268 KB
testcase_21 AC 182 ms
90,368 KB
testcase_22 AC 347 ms
128,256 KB
testcase_23 AC 161 ms
83,968 KB
testcase_24 AC 240 ms
103,552 KB
testcase_25 AC 520 ms
136,544 KB
testcase_26 AC 103 ms
76,672 KB
testcase_27 AC 149 ms
80,768 KB
testcase_28 AC 363 ms
128,256 KB
testcase_29 AC 332 ms
122,496 KB
testcase_30 AC 128 ms
78,064 KB
testcase_31 AC 600 ms
148,296 KB
testcase_32 AC 251 ms
107,904 KB
testcase_33 AC 546 ms
140,588 KB
testcase_34 AC 340 ms
122,368 KB
testcase_35 AC 232 ms
100,608 KB
testcase_36 AC 242 ms
103,808 KB
testcase_37 AC 287 ms
116,864 KB
testcase_38 AC 219 ms
100,224 KB
testcase_39 AC 167 ms
86,004 KB
testcase_40 AC 388 ms
129,408 KB
testcase_41 AC 484 ms
127,376 KB
testcase_42 AC 44 ms
52,352 KB
testcase_43 AC 44 ms
52,864 KB
testcase_44 AC 43 ms
52,864 KB
testcase_45 AC 44 ms
52,608 KB
testcase_46 AC 43 ms
52,736 KB
testcase_47 AC 42 ms
52,352 KB
testcase_48 AC 43 ms
52,224 KB
testcase_49 AC 43 ms
52,608 KB
testcase_50 AC 44 ms
52,352 KB
testcase_51 AC 43 ms
52,224 KB
testcase_52 AC 43 ms
52,480 KB
testcase_53 AC 44 ms
52,608 KB
testcase_54 AC 44 ms
52,736 KB
testcase_55 AC 44 ms
52,608 KB
testcase_56 AC 43 ms
52,352 KB
testcase_57 AC 43 ms
52,224 KB
testcase_58 AC 44 ms
52,352 KB
testcase_59 AC 44 ms
52,608 KB
testcase_60 AC 43 ms
52,480 KB
testcase_61 AC 43 ms
52,608 KB
testcase_62 AC 44 ms
52,864 KB
testcase_63 AC 51 ms
52,096 KB
testcase_64 AC 45 ms
52,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop, heapify

N = int(input())
P = list(map(int, input().split()))

pre = dict()
nex = dict()
for i in range(N):
    if i == 0:
        pre[P[i]] = -1
    else:
        pre[P[i]] = P[i-1]
    if i == N-1:
        nex[P[i]] = -1
    else:
        nex[P[i]] = P[i+1]

que = P[:N-1]
heapify(que)
ans = []
S = set()
while que:
    n = heappop(que)
    if n in S:
        continue
    ans.append(n)
    ans.append(nex[n])
    S.add(n)
    S.add(nex[n])
    if nex[nex[n]] == -1:
        if pre[n] != -1:
            S.add(pre[n])
        nex[pre[n]] = -1
    else:
        nex[pre[n]] = nex[nex[n]]
        pre[nex[nex[n]]] = pre[n]
    pre.pop(n)
    pre.pop(nex[n])
    ne = nex[n]
    nex.pop(n)
    nex.pop(ne)

print(*ans)
0