結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー 👑 KazunKazun
提出日時 2021-01-29 22:04:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 265 ms / 2,000 ms
コード長 489 bytes
コンパイル時間 609 ms
コンパイル使用メモリ 86,920 KB
実行使用メモリ 109,020 KB
最終ジャッジ日時 2023-09-09 15:27:21
合計ジャッジ時間 5,038 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,412 KB
testcase_01 AC 71 ms
71,212 KB
testcase_02 AC 264 ms
79,652 KB
testcase_03 AC 206 ms
79,632 KB
testcase_04 AC 204 ms
79,476 KB
testcase_05 AC 201 ms
108,684 KB
testcase_06 AC 188 ms
108,692 KB
testcase_07 AC 164 ms
109,020 KB
testcase_08 AC 195 ms
108,508 KB
testcase_09 AC 264 ms
107,112 KB
testcase_10 AC 262 ms
107,288 KB
testcase_11 AC 265 ms
107,100 KB
testcase_12 AC 233 ms
107,104 KB
testcase_13 AC 258 ms
107,272 KB
testcase_14 AC 231 ms
107,384 KB
testcase_15 AC 261 ms
107,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def is_Kadomatsu(a,b,c):
    if len({a,b,c})!=3:
        return False

    return b==max(a,b,c) or b==min(a,b,c)

T=int(input())

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

    for _ in range(3):
        DP=[0]*N

        for i in range(2,N):
            DP[i]=DP[i-1]
            if is_Kadomatsu(A[i-2],A[i-1],A[i]):
                DP[i]=max(DP[i],DP[i-3]+A[i-2])
        M=max(DP)
        Max=max(M,Max)

        A=A[1:]+[A[0]]
    print(Max)
0