結果
| 問題 |
No.2740 Old Maid
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-05-07 22:57:49 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 261 ms / 2,000 ms |
| コード長 | 580 bytes |
| コンパイル時間 | 204 ms |
| コンパイル使用メモリ | 82,320 KB |
| 実行使用メモリ | 165,844 KB |
| 最終ジャッジ日時 | 2024-11-30 19:56:12 |
| 合計ジャッジ時間 | 14,105 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 62 |
ソースコード
from collections import defaultdict
n = int(input())
P = list(map(int, input().split()))
G = defaultdict(int)
RG = defaultdict(int)
for i in range(n - 1):
G[P[i]] = P[i + 1]
G[P[n - 1]] = None
for i in range(n - 1, 0, -1):
RG[P[i]] = P[i - 1]
RG[P[0]] = None
ANS = []
for i in range(1, n + 1):
nex = G[i]
if nex is None:
continue
ANS.append(i)
ANS.append(nex)
new_nex = G[nex]
G[i] = None
G[nex] = None
pre = RG[i]
if pre is not None:
G[pre] = new_nex
if new_nex is not None:
RG[new_nex] = pre
print(*ANS)