結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー convexineqconvexineq
提出日時 2021-01-30 08:51:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 547 ms / 2,000 ms
コード長 544 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 87,236 KB
実行使用メモリ 112,848 KB
最終ジャッジ日時 2023-09-10 04:29:42
合計ジャッジ時間 5,985 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,516 KB
testcase_01 AC 76 ms
71,284 KB
testcase_02 AC 547 ms
83,012 KB
testcase_03 AC 251 ms
79,104 KB
testcase_04 AC 316 ms
80,024 KB
testcase_05 AC 193 ms
106,340 KB
testcase_06 AC 191 ms
106,352 KB
testcase_07 AC 170 ms
106,420 KB
testcase_08 AC 196 ms
106,320 KB
testcase_09 AC 238 ms
112,760 KB
testcase_10 AC 240 ms
112,820 KB
testcase_11 AC 235 ms
112,844 KB
testcase_12 AC 229 ms
112,712 KB
testcase_13 AC 233 ms
112,848 KB
testcase_14 AC 230 ms
112,672 KB
testcase_15 AC 227 ms
112,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def is_kadomatsu(a,b,c):
    if a==b or b==c or a==c or a+b+c-max(a,b,c)-min(a,b,c)==b:
        return False
    return True

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