結果

問題 No.2740 Old Maid
ユーザー noriocnorioc
提出日時 2024-04-24 01:37:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 289 ms / 2,000 ms
コード長 1,386 bytes
コンパイル時間 213 ms
コンパイル使用メモリ 82,100 KB
実行使用メモリ 177,496 KB
最終ジャッジ日時 2024-04-24 01:38:10
合計ジャッジ時間 13,221 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 277 ms
177,340 KB
testcase_01 AC 244 ms
177,468 KB
testcase_02 AC 238 ms
177,496 KB
testcase_03 AC 239 ms
173,804 KB
testcase_04 AC 235 ms
173,552 KB
testcase_05 AC 244 ms
173,980 KB
testcase_06 AC 237 ms
177,132 KB
testcase_07 AC 233 ms
173,760 KB
testcase_08 AC 228 ms
177,496 KB
testcase_09 AC 231 ms
177,072 KB
testcase_10 AC 228 ms
177,192 KB
testcase_11 AC 230 ms
176,652 KB
testcase_12 AC 231 ms
138,228 KB
testcase_13 AC 237 ms
146,880 KB
testcase_14 AC 98 ms
92,136 KB
testcase_15 AC 109 ms
98,420 KB
testcase_16 AC 186 ms
119,972 KB
testcase_17 AC 96 ms
90,300 KB
testcase_18 AC 234 ms
139,084 KB
testcase_19 AC 127 ms
97,196 KB
testcase_20 AC 243 ms
158,532 KB
testcase_21 AC 104 ms
95,288 KB
testcase_22 AC 181 ms
119,112 KB
testcase_23 AC 91 ms
86,100 KB
testcase_24 AC 123 ms
96,820 KB
testcase_25 AC 289 ms
164,888 KB
testcase_26 AC 65 ms
68,324 KB
testcase_27 AC 82 ms
81,572 KB
testcase_28 AC 184 ms
119,496 KB
testcase_29 AC 175 ms
114,904 KB
testcase_30 AC 69 ms
71,692 KB
testcase_31 AC 272 ms
176,740 KB
testcase_32 AC 129 ms
100,480 KB
testcase_33 AC 263 ms
167,100 KB
testcase_34 AC 182 ms
114,592 KB
testcase_35 AC 117 ms
95,376 KB
testcase_36 AC 122 ms
97,196 KB
testcase_37 AC 161 ms
107,520 KB
testcase_38 AC 114 ms
94,508 KB
testcase_39 AC 92 ms
89,364 KB
testcase_40 AC 217 ms
129,328 KB
testcase_41 AC 249 ms
157,824 KB
testcase_42 AC 39 ms
52,004 KB
testcase_43 AC 40 ms
52,536 KB
testcase_44 AC 40 ms
53,424 KB
testcase_45 AC 42 ms
52,704 KB
testcase_46 AC 40 ms
52,624 KB
testcase_47 AC 41 ms
52,360 KB
testcase_48 AC 41 ms
53,284 KB
testcase_49 AC 41 ms
52,552 KB
testcase_50 AC 43 ms
53,116 KB
testcase_51 AC 40 ms
53,296 KB
testcase_52 AC 42 ms
52,492 KB
testcase_53 AC 40 ms
52,504 KB
testcase_54 AC 42 ms
52,728 KB
testcase_55 AC 42 ms
53,280 KB
testcase_56 AC 40 ms
52,676 KB
testcase_57 AC 41 ms
52,680 KB
testcase_58 AC 40 ms
52,608 KB
testcase_59 AC 40 ms
52,888 KB
testcase_60 AC 41 ms
54,228 KB
testcase_61 AC 39 ms
52,584 KB
testcase_62 AC 40 ms
54,012 KB
testcase_63 AC 39 ms
51,944 KB
testcase_64 AC 41 ms
53,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Node:
    def __init__(self, x):
        self.x = x
        self.prev = None
        self.next = None


class LinkedList:
    def __init__(self):
        self.front = Node(None)
        self.back = self.front
        pass

    def append(self, x):
        node = Node(x)
        node.prev = self.back
        self.back.next = node
        self.back = node
        return node

    def appendleft(self, x):
        front = self.front
        node = Node(x)
        next = front.next
        if next is None:
            node.prev = front
            front.next = node
        else:
            next.prev = node
            node.next = next

            node.prev = front
            front.next = node

        self.front = node
        return node

    def remove(self, node: Node):
        prev = node.prev
        next = node.next
        assert prev is not None
        prev.next = next
        if next is not None:
            next.prev = prev


N = int(input())
P = list(map(lambda x: int(x)-1, input().split()))

ll = LinkedList()
d = {}
for p in P:
    node = ll.append(p)
    d[p] = node

used = set()
ans = []
for i in range(N):
    if i in used: continue
    node = d[i]
    next = node.next
    if next is None: continue
    ans.append(node.x + 1)
    ans.append(next.x + 1)
    used.add(node.x)
    used.add(next.x)
    ll.remove(node)
    ll.remove(next)

print(*ans)
0