結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
権限があれば一括ダウンロードができます

ソースコード

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)
print(1)
0