結果
| 問題 |
No.1804 Intersection of LIS
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-01-25 01:17:24 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 324 ms / 2,000 ms |
| コード長 | 716 bytes |
| コンパイル時間 | 233 ms |
| コンパイル使用メモリ | 82,920 KB |
| 実行使用メモリ | 210,368 KB |
| 最終ジャッジ日時 | 2024-12-15 05:59:45 |
| 合計ジャッジ時間 | 9,119 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 37 |
ソースコード
from bisect import bisect_left
n = int(input())
P = list(map(int, input().split()))
def f(P):
bef = [-1] * n
lis = [0] * n
lst = []
pos = []
for i, p in enumerate(P):
j = bisect_left(lst, p)
if len(lst) == j:
lst.append(p)
pos.append(i)
else:
lst[j] = p
pos[j] = i
lis[i] = j
if j != 0:
bef[i] = pos[j - 1]
p = pos[-1]
left = []
while p != -1:
left.append(P[p])
p = bef[p]
return left
left = f(P)[::-1]
P = P[::-1]
P = [-p for p in P]
right = f(P)
right = [-p for p in right]
ans = [l for l, r in zip(left, right) if l == r]
print(len(ans))
print(*ans)