結果
| 問題 | No.2740 Old Maid |
| コンテスト | |
| ユーザー |
sunton
|
| 提出日時 | 2024-05-27 23:10:04 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 381 ms / 2,000 ms |
| コード長 | 498 bytes |
| コンパイル時間 | 220 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 39,132 KB |
| 最終ジャッジ日時 | 2024-12-20 20:36:27 |
| 合計ジャッジ時間 | 17,429 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 62 |
ソースコード
N = int(input())
P = list(map(int, input().split()))
pre = [-1] * (N + 1)
nex = [-1] * (N + 1)
for i in range(1, N - 1):
pre[P[i]] = P[i - 1]
nex[P[i]] = P[i + 1]
pre[P[-1]] = P[-2]
nex[P[0]] = P[1]
nil = 0
pre[P[0]] = nil
nex[P[-1]] = nil
res = []
for i in range(1, N + 1):
if nex[i] == nil:
continue
res.extend([i, nex[i]])
nex[pre[i]] = nex[nex[i]]
pre[nex[nex[i]]] = pre[i]
# 存在確認用
nex[nex[i]] = nex[i] = nil
print(' '.join(map(str, res)))
sunton