結果

問題 No.209 Longest Mountain Subsequence
ユーザー chocoruskchocorusk
提出日時 2020-09-18 13:55:25
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 988 ms / 2,000 ms
コード長 836 bytes
コンパイル時間 141 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-06-22 07:58:04
合計ジャッジ時間 3,951 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

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, ai in enumerate(a):
            mn=min([ai-aj for aj, dpj in zip(a[:i], dp[:i]) if dpj<ai-aj], default=INF)
            if newdp[i]>mn:
                newdp[i]=mn
        dp=newdp
        end=True
        for i in range(n):
            if dp[i]<INF:
                res[i]=c
                end=False
        if end:
            break
    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()
0