結果

問題 No.2740 Old Maid
ユーザー tassei903tassei903
提出日時 2024-04-12 00:08:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 697 bytes
コンパイル時間 235 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 114,560 KB
最終ジャッジ日時 2024-04-17 02:52:30
合計ジャッジ時間 10,412 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 145 ms
114,432 KB
testcase_01 AC 145 ms
114,304 KB
testcase_02 AC 146 ms
114,560 KB
testcase_03 AC 151 ms
114,432 KB
testcase_04 AC 148 ms
114,304 KB
testcase_05 AC 153 ms
114,432 KB
testcase_06 AC 142 ms
114,432 KB
testcase_07 AC 150 ms
114,048 KB
testcase_08 AC 153 ms
114,536 KB
testcase_09 AC 145 ms
114,432 KB
testcase_10 AC 143 ms
114,304 KB
testcase_11 AC 144 ms
114,432 KB
testcase_12 AC 136 ms
102,332 KB
testcase_13 AC 142 ms
114,176 KB
testcase_14 AC 76 ms
83,320 KB
testcase_15 AC 80 ms
86,428 KB
testcase_16 AC 124 ms
100,224 KB
testcase_17 AC 78 ms
82,304 KB
testcase_18 AC 142 ms
106,240 KB
testcase_19 AC 92 ms
92,288 KB
testcase_20 AC 147 ms
108,928 KB
testcase_21 AC 81 ms
84,864 KB
testcase_22 AC 116 ms
103,936 KB
testcase_23 AC 82 ms
80,552 KB
testcase_24 AC 90 ms
92,160 KB
testcase_25 AC 157 ms
109,696 KB
testcase_26 AC 56 ms
66,944 KB
testcase_27 AC 74 ms
77,952 KB
testcase_28 AC 114 ms
96,976 KB
testcase_29 AC 107 ms
102,144 KB
testcase_30 AC 67 ms
73,600 KB
testcase_31 AC 167 ms
114,176 KB
testcase_32 AC 100 ms
92,288 KB
testcase_33 AC 156 ms
110,336 KB
testcase_34 AC 109 ms
101,404 KB
testcase_35 AC 88 ms
90,112 KB
testcase_36 AC 90 ms
92,224 KB
testcase_37 AC 106 ms
97,920 KB
testcase_38 AC 86 ms
89,380 KB
testcase_39 AC 82 ms
81,536 KB
testcase_40 AC 121 ms
107,008 KB
testcase_41 AC 146 ms
108,928 KB
testcase_42 AC 36 ms
51,968 KB
testcase_43 AC 36 ms
52,224 KB
testcase_44 AC 36 ms
52,480 KB
testcase_45 AC 36 ms
51,968 KB
testcase_46 AC 36 ms
51,968 KB
testcase_47 AC 36 ms
51,968 KB
testcase_48 AC 36 ms
51,968 KB
testcase_49 AC 45 ms
52,480 KB
testcase_50 AC 38 ms
52,480 KB
testcase_51 AC 38 ms
52,352 KB
testcase_52 AC 37 ms
52,224 KB
testcase_53 AC 37 ms
52,736 KB
testcase_54 AC 36 ms
51,712 KB
testcase_55 AC 36 ms
52,224 KB
testcase_56 AC 36 ms
51,712 KB
testcase_57 AC 36 ms
52,224 KB
testcase_58 AC 36 ms
52,096 KB
testcase_59 AC 37 ms
52,352 KB
testcase_60 AC 35 ms
51,712 KB
testcase_61 AC 34 ms
51,968 KB
testcase_62 AC 35 ms
52,352 KB
testcase_63 AC 34 ms
52,096 KB
testcase_64 AC 36 ms
52,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
p = [x-1 for x in list(map(int, input().split()))]
invp = [-1]*n
for i in range(n):
    invp[p[i]] = i


next = [-1] * n
prev = [-1] * n
for i in range(n):
    next[i] = (i+1)%n
    prev[i] = (i-1)%n

def remove(x):
    prev[next[x]] = prev[x]
    next[prev[x]] = next[x]


removed = [0] * n
removed[p[-1]] = 1

last = n-1
ans = []
x = 0
for i in range(n//2):
    while removed[x]:
        x += 1
    
    ans.append(x+1)
    y = p[next[invp[x]]]
    ans.append(y+1)
    remove(invp[x])
    remove(invp[y])
    removed[x] = 1
    removed[y] = 1
    if invp[y] == last and i < n//2-1:
        while removed[p[last]]:
            last -= 1
        removed[p[last]] = 1

print(*ans)
0