結果
問題 |
No.209 Longest Mountain Subsequence
|
ユーザー |
![]() |
提出日時 | 2020-09-18 14:03:38 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 731 ms / 2,000 ms |
コード長 | 852 bytes |
コンパイル時間 | 115 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 10,880 KB |
最終ジャッジ日時 | 2024-06-22 07:58:29 |
合計ジャッジ時間 | 3,104 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 6 |
ソースコード
import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines import itertools t=int(readline()) def myon(a): INF=10**9+7 n=len(a) dp=[0]*n res=[1]*n for c in range(2, n+1): newdp=[INF]*n for i in range(n): ai=a[i] for j in range(i): aj=a[j] if dp[j]<ai-aj and ai-aj<newdp[i]: newdp[i]=ai-aj end=True for i in range(n): if newdp[i]<INF: res[i]=c end=False if end: break dp=newdp return res def solve(): n=int(readline()) a=list(map(int, readline().split())) x=myon(a) a=a[::-1] y=myon(a) y=y[::-1] print(max(p+q-1 for p, q in zip(x, y))) for _ in range(t): solve()