結果
問題 | No.2740 Old Maid |
ユーザー |
|
提出日時 | 2024-04-21 01:19:41 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 353 ms / 2,000 ms |
コード長 | 503 bytes |
コンパイル時間 | 145 ms |
コンパイル使用メモリ | 82,836 KB |
実行使用メモリ | 119,552 KB |
最終ジャッジ日時 | 2024-10-12 23:39:53 |
合計ジャッジ時間 | 12,015 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 62 |
ソースコード
N = int(input()) p = list(map(int, input().split())) prev = [-1] + list(range(N-1)) next = list(range(1, N)) + [-1] sorted_args = sorted(range(N), key=lambda x: p[x]) left = [True]*N ans = [] for x in sorted_args: if not left[x]: continue if next[x] == -1: continue y = next[x] left[x] = False left[y] = False pr = prev[x] n = next[y] if pr != -1: next[pr] = n if n != -1: prev[n] = pr ans.extend([p[x], p[y]]) print(*ans)