結果
問題 | No.2740 Old Maid |
ユーザー | norioc |
提出日時 | 2024-04-25 00:06:32 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 288 ms / 2,000 ms |
コード長 | 2,083 bytes |
コンパイル時間 | 173 ms |
コンパイル使用メモリ | 82,528 KB |
実行使用メモリ | 175,280 KB |
最終ジャッジ日時 | 2024-11-07 09:29:25 |
合計ジャッジ時間 | 12,334 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 218 ms
174,572 KB |
testcase_01 | AC | 224 ms
174,364 KB |
testcase_02 | AC | 220 ms
174,900 KB |
testcase_03 | AC | 226 ms
172,928 KB |
testcase_04 | AC | 227 ms
171,072 KB |
testcase_05 | AC | 225 ms
171,168 KB |
testcase_06 | AC | 222 ms
173,888 KB |
testcase_07 | AC | 230 ms
171,200 KB |
testcase_08 | AC | 222 ms
174,264 KB |
testcase_09 | AC | 244 ms
174,176 KB |
testcase_10 | AC | 221 ms
174,656 KB |
testcase_11 | AC | 224 ms
175,280 KB |
testcase_12 | AC | 224 ms
140,908 KB |
testcase_13 | AC | 228 ms
149,716 KB |
testcase_14 | AC | 101 ms
91,396 KB |
testcase_15 | AC | 112 ms
92,008 KB |
testcase_16 | AC | 185 ms
122,672 KB |
testcase_17 | AC | 95 ms
85,080 KB |
testcase_18 | AC | 224 ms
142,604 KB |
testcase_19 | AC | 126 ms
98,136 KB |
testcase_20 | AC | 255 ms
161,564 KB |
testcase_21 | AC | 102 ms
88,192 KB |
testcase_22 | AC | 183 ms
122,080 KB |
testcase_23 | AC | 93 ms
86,248 KB |
testcase_24 | AC | 128 ms
98,032 KB |
testcase_25 | AC | 272 ms
167,448 KB |
testcase_26 | AC | 68 ms
68,992 KB |
testcase_27 | AC | 85 ms
81,664 KB |
testcase_28 | AC | 184 ms
122,544 KB |
testcase_29 | AC | 181 ms
117,724 KB |
testcase_30 | AC | 71 ms
72,704 KB |
testcase_31 | AC | 288 ms
173,316 KB |
testcase_32 | AC | 131 ms
101,240 KB |
testcase_33 | AC | 269 ms
168,504 KB |
testcase_34 | AC | 173 ms
116,392 KB |
testcase_35 | AC | 120 ms
96,244 KB |
testcase_36 | AC | 125 ms
98,464 KB |
testcase_37 | AC | 159 ms
109,112 KB |
testcase_38 | AC | 114 ms
95,328 KB |
testcase_39 | AC | 97 ms
89,088 KB |
testcase_40 | AC | 203 ms
132,124 KB |
testcase_41 | AC | 249 ms
160,812 KB |
testcase_42 | AC | 39 ms
52,224 KB |
testcase_43 | AC | 39 ms
52,224 KB |
testcase_44 | AC | 40 ms
52,736 KB |
testcase_45 | AC | 40 ms
52,480 KB |
testcase_46 | AC | 41 ms
52,472 KB |
testcase_47 | AC | 40 ms
52,864 KB |
testcase_48 | AC | 40 ms
52,616 KB |
testcase_49 | AC | 42 ms
52,480 KB |
testcase_50 | AC | 40 ms
52,736 KB |
testcase_51 | AC | 39 ms
52,224 KB |
testcase_52 | AC | 39 ms
52,096 KB |
testcase_53 | AC | 40 ms
52,352 KB |
testcase_54 | AC | 40 ms
52,224 KB |
testcase_55 | AC | 40 ms
52,864 KB |
testcase_56 | AC | 40 ms
52,352 KB |
testcase_57 | AC | 41 ms
52,736 KB |
testcase_58 | AC | 43 ms
52,608 KB |
testcase_59 | AC | 43 ms
52,864 KB |
testcase_60 | AC | 42 ms
52,864 KB |
testcase_61 | AC | 42 ms
52,352 KB |
testcase_62 | AC | 42 ms
52,736 KB |
testcase_63 | AC | 40 ms
52,864 KB |
testcase_64 | AC | 40 ms
52,480 KB |
ソースコード
class Node: def __init__(self, val): self.val = val self.prev = None self.next = None class LinkedList: def __init__(self): self.front = None self.back = None self.size = 0 # a の後ろに b をつなぐ def _join(self, a: Node, b: Node): a.next = b b.prev = a def append(self, val) -> Node: node = Node(val) if self.front is None: self.front = self.back = node else: self._join(self.back, node) self.back = node self.size += 1 return node def appendleft(self, val) -> Node: node = Node(val) if self.front is None: self.front = self.back = node else: self._join(node, self.front) self.front = node self.size += 1 return node def remove(self, node: Node): assert self.size > 0 if self.size == 1: self.front = self.back = None elif node is self.front: self.front = self.front.next self.front.prev = None elif node is self.back: self.back = self.back.prev self.back.next = None else: prev = node.prev next = node.next prev.next = next next.prev = prev self.size -= 1 def __len__(self): return self.size def __iter__(self): if self.front is None: return node = self.front while node is not None: yield node.val node = node.next N = int(input()) P = list(map(lambda x: int(x)-1, input().split())) ll = LinkedList() p2node = {} for p in P: p2node[p] = ll.append(p) used = set() ans = [] for i in range(N): if i in used: continue node = p2node[i] next = node.next if next is None: continue # 2 つの要素が連蔵していない ans.append(node.val + 1) ans.append(next.val + 1) ll.remove(node) ll.remove(next) used.add(node.val) used.add(next.val) print(*ans)