結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー lloyzlloyz
提出日時 2022-06-02 21:56:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 227 ms / 2,000 ms
コード長 600 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 110,748 KB
最終ジャッジ日時 2023-10-21 01:19:58
合計ジャッジ時間 3,937 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,308 KB
testcase_01 AC 40 ms
53,308 KB
testcase_02 AC 227 ms
76,640 KB
testcase_03 AC 170 ms
77,216 KB
testcase_04 AC 173 ms
76,564 KB
testcase_05 AC 167 ms
110,748 KB
testcase_06 AC 169 ms
110,748 KB
testcase_07 AC 139 ms
110,748 KB
testcase_08 AC 169 ms
110,748 KB
testcase_09 AC 191 ms
109,160 KB
testcase_10 AC 193 ms
109,160 KB
testcase_11 AC 194 ms
109,148 KB
testcase_12 AC 190 ms
109,148 KB
testcase_13 AC 190 ms
109,148 KB
testcase_14 AC 195 ms
109,160 KB
testcase_15 AC 195 ms
109,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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