結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-01-29 22:51:05
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 278 ms / 2,000 ms
コード長 438 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 86,872 KB
実行使用メモリ 112,512 KB
最終ジャッジ日時 2023-09-09 16:29:02
合計ジャッジ時間 5,213 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,384 KB
testcase_01 AC 72 ms
71,440 KB
testcase_02 AC 264 ms
79,596 KB
testcase_03 AC 242 ms
80,396 KB
testcase_04 AC 278 ms
80,384 KB
testcase_05 AC 253 ms
111,824 KB
testcase_06 AC 260 ms
111,724 KB
testcase_07 AC 175 ms
112,512 KB
testcase_08 AC 244 ms
111,936 KB
testcase_09 AC 274 ms
110,296 KB
testcase_10 AC 275 ms
110,976 KB
testcase_11 AC 275 ms
110,764 KB
testcase_12 AC 270 ms
110,520 KB
testcase_13 AC 272 ms
110,504 KB
testcase_14 AC 273 ms
110,492 KB
testcase_15 AC 273 ms
110,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

t = int(input())
for _ in range(t):
    n = int(input())
    A = list(map(int,input().split()))
    ans = 0
    for j in range(3):
        a = A[j:]+A[:j]
        dp = [0]*(n+5)
        for i in range(n-2):
            dp[i] = max(dp[i],dp[i-1])
            x = a[i:i+3]
            if len(set(x)) == 3 and (min(x) == x[1] or max(x) == x[1]):
                dp[i+3] = max(dp[i+3],dp[i]+a[i])
        ans = max(ans,max(dp))
    print(ans)
0