結果
問題 | No.2740 Old Maid |
ユーザー |
![]() |
提出日時 | 2024-04-20 10:30:29 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 250 ms / 2,000 ms |
コード長 | 472 bytes |
コンパイル時間 | 386 ms |
コンパイル使用メモリ | 82,688 KB |
実行使用メモリ | 143,468 KB |
最終ジャッジ日時 | 2024-10-12 06:03:09 |
合計ジャッジ時間 | 11,914 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 62 |
ソースコード
N = int(input()) P = list(map(int, input().split())) + ["$"] nex = [-1] * (N + 1) pre = [-1] * (N + 1) for i in range(N): nex[P[i]] = P[i + 1] pre[P[i]] = P[i - 1] ans = [] S = set() for i in range(1, N + 1): if nex[i] == "$" or i in S: continue ans.append(i) ans.append(nex[i]) S.add(i) S.add(nex[i]) p = pre[i] n = nex[nex[i]] if p != "$": nex[p] = n if n != "$": pre[n] = p print(*ans)