結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー convexineqconvexineq
提出日時 2021-01-30 08:55:22
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 532 bytes
コンパイル時間 535 ms
コンパイル使用メモリ 86,968 KB
実行使用メモリ 112,872 KB
最終ジャッジ日時 2023-09-10 04:39:49
合計ジャッジ時間 4,992 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 71 ms
71,376 KB
testcase_02 AC 528 ms
85,676 KB
testcase_03 AC 237 ms
79,280 KB
testcase_04 AC 287 ms
79,292 KB
testcase_05 AC 189 ms
106,444 KB
testcase_06 AC 184 ms
106,360 KB
testcase_07 AC 163 ms
106,240 KB
testcase_08 AC 178 ms
106,468 KB
testcase_09 AC 221 ms
112,704 KB
testcase_10 AC 218 ms
112,872 KB
testcase_11 AC 221 ms
112,860 KB
testcase_12 AC 216 ms
112,684 KB
testcase_13 AC 215 ms
112,792 KB
testcase_14 AC 208 ms
112,872 KB
testcase_15 AC 216 ms
112,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def is_kadomatsu(a,b,c):
    return a!=b and b!=c and c!=a and (b==max(a,b,c) or b==min(a,b,c))

def solve(a,start,n):
    dp = [0]*(n+1)
    for i in range(n):
        dp[i+1] = max(dp[i+1],dp[i])
        idx = i+start
        if i+3 <= n and is_kadomatsu(*a[idx:idx+3]):
            dp[i+3] = max(dp[i+3],dp[i]+a[idx])
    return dp[-1]

T = int(input())
for _ in range(T):
    n = int(input())
    *a, = map(int,input().split())
    a += a[:2]
    ans = max(solve(a,0,n),solve(a,1,n),solve(a,2,n))
    print(ans)
if T==3:print(1)
0