結果

問題 No.2740 Old Maid
ユーザー norioc
提出日時 2024-04-24 01:37:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 266 ms / 2,000 ms
コード長 1,386 bytes
コンパイル時間 242 ms
コンパイル使用メモリ 82,440 KB
実行使用メモリ 177,736 KB
最終ジャッジ日時 2024-11-06 08:16:47
合計ジャッジ時間 12,149 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 62
権限があれば一括ダウンロードができます

ソースコード

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)
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0