結果

問題 No.209 Longest Mountain Subsequence
ユーザー maspymaspy
提出日時 2020-03-06 15:10:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,614 ms / 2,000 ms
コード長 807 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 43,864 KB
最終ジャッジ日時 2024-04-22 03:55:12
合計ジャッジ時間 8,555 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 982 ms
43,504 KB
testcase_01 AC 935 ms
43,764 KB
testcase_02 AC 910 ms
43,768 KB
testcase_03 AC 1,609 ms
43,760 KB
testcase_04 AC 1,614 ms
43,388 KB
testcase_05 AC 900 ms
43,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

# %%
T = int(readline())


# %%
def calc_from_left(A):
    N = len(A)
    dp = np.zeros((N, N), np.int32)
    for i in range(1, N):
        B = A[:i]
        cond1 = (A[i] > B)[:, None] & (B[:, None] >= B[None, :])
        cond2 = (A[i] - B)[:, None] > (B[:, None] - B[None, :])
        cond = cond1 & cond2
        dp[i, :i] = ((dp[:i, :i] + 1) * cond).max(axis=1)
    return dp.max(axis=1)


def solve():
    N = int(readline())
    A = np.array(readline().split(), np.int64)
    dp1 = calc_from_left(A)
    dp2 = calc_from_left(A[::-1])[::-1]
    return max(x + y for x, y in zip(dp1, dp2)) + 1


# %%
for _ in range(T):
    print(solve())
0