結果

問題 No.209 Longest Mountain Subsequence
ユーザー chocoruskchocorusk
提出日時 2020-09-18 14:03:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 659 ms / 2,000 ms
コード長 852 bytes
コンパイル時間 102 ms
コンパイル使用メモリ 10,920 KB
実行使用メモリ 8,400 KB
最終ジャッジ日時 2023-09-04 08:50:06
合計ジャッジ時間 3,016 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 252 ms
8,232 KB
testcase_01 AC 229 ms
8,276 KB
testcase_02 AC 212 ms
8,352 KB
testcase_03 AC 656 ms
8,280 KB
testcase_04 AC 659 ms
8,360 KB
testcase_05 AC 57 ms
8,400 KB
権限があれば一括ダウンロードができます

ソースコード

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 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()
0