結果
問題 |
No.1368 サイクルの中に眠る門松列
|
ユーザー |
|
提出日時 | 2022-06-02 21:56:38 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 208 ms / 2,000 ms |
コード長 | 600 bytes |
コンパイル時間 | 294 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 111,488 KB |
最終ジャッジ日時 | 2024-09-21 02:09:27 |
合計ジャッジ時間 | 3,486 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 15 |
ソースコード
t = int(input()) for _ in range(t): n = int(input()) A = list(map(int, input().split())) A += A ans = 0 for f in range(3): DP = [0 for _ in range(n + 1)] for i in range(3, n + 1): if len(set(A[f + i - 3:f + i])) < 3: DP[i] = DP[i - 1] else: if A[f + i - 3] < A[f + i - 2] > A[f + i - 1] or A[f + i - 3] > A[f + i - 2] < A[f + i - 1]: DP[i] = max(DP[i - 1], DP[i - 3] + A[f + i - 3]) else: DP[i] = DP[i - 1] ans = max(ans, DP[n]) print(ans)