結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー c-yanc-yan
提出日時 2021-01-29 22:26:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,237 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 30,264 KB
最終ジャッジ日時 2023-09-09 15:56:40
合計ジャッジ時間 5,931 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,120 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 489 ms
30,128 KB
testcase_06 WA -
testcase_07 AC 158 ms
30,236 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 233 ms
21,536 KB
testcase_11 AC 232 ms
21,576 KB
testcase_12 AC 232 ms
21,500 KB
testcase_13 AC 552 ms
21,492 KB
testcase_14 AC 233 ms
21,488 KB
testcase_15 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def is_kadomatsu(a, b, c):
    if a == b or b == c or a == c:
        return False
    return min([a, b, c]) == b or max([a, b, c]) == b


def solve():
    a=A
    dp = [0] * (N + 1)
    for i in range(N + 1):
        if i != 0:
            dp[i] = max(dp[i], dp[i - 1])
        if i <= N - 3:
            if is_kadomatsu(a[i], a[i + 1], a[i + 2]):
                dp[i + 3] = dp[i] + a[i]
    result = dp[N - 1]
    if is_kadomatsu(a[N - 1], a[0], a[1]):
        dp = [0] * (N + 1)
        dp[2] = a[N - 1]
        for i in range(2, N + 1):
            dp[i] = max(dp[i], dp[i - 1])
            if i <= N - 4:
                if is_kadomatsu(a[i], a[i + 1], a[i + 2]):
                    dp[i + 3] = dp[i] + a[i]
        result = max(result, dp[N - 1])
    if is_kadomatsu(a[N - 2], a[N - 1], a[0]):
        dp = [0] * (N + 1)
        dp[1] = a[N - 1]
        for i in range(1, N + 1):
            dp[i] = max(dp[i], dp[i - 1])
            if i <= N - 5:
                if is_kadomatsu(a[i], a[i + 1], a[i + 2]):
                    dp[i + 3] = dp[i] + a[i]
        result = max(result, dp[N - 1])
    return result


T = int(input())
for _ in range(T):
    N = int(input())
    A = list(map(int, input().split()))
    print(solve())
0