結果
| 問題 |
No.209 Longest Mountain Subsequence
|
| コンテスト | |
| ユーザー |
maspy
|
| 提出日時 | 2020-03-06 15:10:27 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 1,590 ms / 2,000 ms |
| コード長 | 807 bytes |
| コンパイル時間 | 82 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 43,868 KB |
| 最終ジャッジ日時 | 2024-10-14 02:49:18 |
| 合計ジャッジ時間 | 8,378 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 |
ソースコード
#!/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())
maspy