結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー KudeKude
提出日時 2021-01-29 21:39:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 270 ms / 2,000 ms
コード長 649 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 86,916 KB
実行使用メモリ 107,604 KB
最終ジャッジ日時 2023-09-09 14:58:31
合計ジャッジ時間 3,816 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
71,372 KB
testcase_01 AC 69 ms
71,260 KB
testcase_02 AC 270 ms
80,756 KB
testcase_03 AC 186 ms
79,596 KB
testcase_04 AC 172 ms
78,460 KB
testcase_05 AC 128 ms
107,364 KB
testcase_06 AC 132 ms
107,564 KB
testcase_07 AC 115 ms
107,604 KB
testcase_08 AC 138 ms
107,276 KB
testcase_09 AC 183 ms
105,480 KB
testcase_10 AC 182 ms
105,668 KB
testcase_11 AC 191 ms
105,476 KB
testcase_12 AC 196 ms
105,740 KB
testcase_13 AC 188 ms
105,432 KB
testcase_14 AC 191 ms
105,400 KB
testcase_15 AC 189 ms
105,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    a.append(a[0])
    a.append(a[1])
    ans = 0
    for k in range(3):
        dp = [0, 0, 0]
        for i in range(k, n - 2 + k):
            if a[i] != a[i+2] and (a[i+1] > max(a[i], a[i+2]) or a[i+1] < min(a[i], a[i+2])):
                dp = [
                    max(dp[0], dp[1]),
                    dp[2],
                    dp[0] + a[i]
                ]
            else:
                dp = [
                    max(dp[0], dp[1]),
                    dp[2],
                    0
                ]
        ans = max(ans, *dp)
    print(ans)
0