結果

問題 No.2740 Old Maid
ユーザー ntudantuda
提出日時 2024-04-29 21:37:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 537 bytes
コンパイル時間 261 ms
コンパイル使用メモリ 82,408 KB
実行使用メモリ 120,448 KB
最終ジャッジ日時 2024-04-29 21:37:40
合計ジャッジ時間 12,165 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
111,464 KB
testcase_01 AC 136 ms
110,976 KB
testcase_02 AC 131 ms
110,976 KB
testcase_03 AC 135 ms
111,232 KB
testcase_04 AC 135 ms
110,720 KB
testcase_05 AC 134 ms
111,488 KB
testcase_06 AC 134 ms
111,280 KB
testcase_07 AC 132 ms
111,216 KB
testcase_08 AC 147 ms
110,976 KB
testcase_09 AC 133 ms
110,848 KB
testcase_10 AC 130 ms
111,040 KB
testcase_11 AC 130 ms
110,976 KB
testcase_12 AC 118 ms
114,176 KB
testcase_13 AC 120 ms
115,968 KB
testcase_14 AC 68 ms
82,816 KB
testcase_15 AC 74 ms
85,504 KB
testcase_16 AC 116 ms
105,728 KB
testcase_17 AC 69 ms
81,920 KB
testcase_18 AC 116 ms
112,512 KB
testcase_19 AC 83 ms
91,136 KB
testcase_20 AC 132 ms
120,440 KB
testcase_21 AC 71 ms
84,080 KB
testcase_22 AC 102 ms
105,720 KB
testcase_23 AC 61 ms
77,280 KB
testcase_24 AC 81 ms
90,828 KB
testcase_25 AC 131 ms
120,448 KB
testcase_26 AC 62 ms
65,024 KB
testcase_27 AC 60 ms
72,832 KB
testcase_28 AC 102 ms
105,344 KB
testcase_29 AC 99 ms
102,144 KB
testcase_30 AC 56 ms
67,712 KB
testcase_31 AC 141 ms
110,720 KB
testcase_32 AC 86 ms
93,312 KB
testcase_33 AC 132 ms
119,040 KB
testcase_34 AC 99 ms
102,144 KB
testcase_35 AC 83 ms
88,960 KB
testcase_36 AC 94 ms
91,008 KB
testcase_37 AC 94 ms
98,944 KB
testcase_38 AC 78 ms
88,504 KB
testcase_39 AC 64 ms
78,720 KB
testcase_40 AC 109 ms
109,952 KB
testcase_41 AC 128 ms
119,936 KB
testcase_42 AC 37 ms
51,712 KB
testcase_43 AC 36 ms
52,096 KB
testcase_44 AC 36 ms
52,408 KB
testcase_45 AC 37 ms
52,096 KB
testcase_46 AC 37 ms
52,224 KB
testcase_47 AC 37 ms
51,456 KB
testcase_48 AC 37 ms
51,712 KB
testcase_49 AC 38 ms
52,480 KB
testcase_50 AC 37 ms
51,712 KB
testcase_51 AC 36 ms
51,840 KB
testcase_52 AC 40 ms
52,496 KB
testcase_53 AC 37 ms
52,096 KB
testcase_54 AC 36 ms
51,840 KB
testcase_55 AC 38 ms
51,840 KB
testcase_56 AC 37 ms
52,480 KB
testcase_57 AC 36 ms
51,840 KB
testcase_58 AC 36 ms
52,096 KB
testcase_59 AC 37 ms
51,584 KB
testcase_60 AC 38 ms
51,840 KB
testcase_61 AC 38 ms
51,584 KB
testcase_62 AC 37 ms
52,352 KB
testcase_63 AC 37 ms
51,712 KB
testcase_64 AC 37 ms
51,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int, input().split()))
P = [0] * (N + 1)
pre = [-1] * (N + 1)
post = [-1] * (N + 1)
ans = []

for i, a in enumerate(A):
    P[a] = i
    if i > 0:
        pre[a] = A[i - 1]
    if i < N - 1:
        post[a] = A[i + 1]

for i in range(1, N + 1):
    if P[i] == -1 or post[i] == -1:
        continue
    x = P[i]
    y = post[i]
    P[i] = -1
    P[y] = -1
    if pre[i] != -1:
        post[pre[i]] = post[y]
    if post[y] != -1:
        pre[post[y]] = pre[i]
    ans.append(i)
    ans.append(y)
print(*ans)
0