結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー 👑 rin204rin204
提出日時 2022-01-18 18:34:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 314 ms / 2,000 ms
コード長 550 bytes
コンパイル時間 487 ms
コンパイル使用メモリ 82,376 KB
実行使用メモリ 108,544 KB
最終ジャッジ日時 2024-05-02 19:25:53
合計ジャッジ時間 4,551 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,096 KB
testcase_01 AC 36 ms
52,496 KB
testcase_02 AC 314 ms
79,636 KB
testcase_03 AC 208 ms
78,124 KB
testcase_04 AC 245 ms
78,336 KB
testcase_05 AC 160 ms
108,544 KB
testcase_06 AC 163 ms
107,904 KB
testcase_07 AC 138 ms
108,160 KB
testcase_08 AC 169 ms
107,932 KB
testcase_09 AC 180 ms
106,328 KB
testcase_10 AC 185 ms
106,168 KB
testcase_11 AC 179 ms
106,112 KB
testcase_12 AC 181 ms
106,240 KB
testcase_13 AC 179 ms
105,984 KB
testcase_14 AC 185 ms
105,988 KB
testcase_15 AC 190 ms
105,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def kado(a, b, c):
    if len(set((a, b, c))) != 3:
        return False
    return b in [max(a, b, c), min(a, b, c)]

def solve():
    n = int(input())
    A = list(map(int, input().split()))
    ans = 0
    for _ in range(3):
        dp = [0] * (n + 1)
        for i in range(3, n + 1):
            a, b, c = A[i - 3:i]
            dp[i] = dp[i - 1]
            if kado(a, b, c):
                dp[i] = max(dp[i], dp[i - 3] + a)
        ans = max(ans, dp[-1])
        A = A[1:] + A[:1]
    print(ans)
    
for _ in range(int(input())):
    solve()
0