結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー ytftytft
提出日時 2022-03-23 00:34:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 481 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 82,256 KB
実行使用メモリ 108,288 KB
最終ジャッジ日時 2024-04-19 02:50:30
合計ジャッジ時間 3,342 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,224 KB
testcase_01 AC 41 ms
51,840 KB
testcase_02 AC 197 ms
78,600 KB
testcase_03 AC 147 ms
78,060 KB
testcase_04 AC 149 ms
77,628 KB
testcase_05 AC 121 ms
108,032 KB
testcase_06 AC 120 ms
108,032 KB
testcase_07 AC 108 ms
108,032 KB
testcase_08 AC 118 ms
108,288 KB
testcase_09 AC 139 ms
106,368 KB
testcase_10 AC 142 ms
106,240 KB
testcase_11 AC 138 ms
106,240 KB
testcase_12 AC 138 ms
106,496 KB
testcase_13 AC 139 ms
105,984 KB
testcase_14 AC 138 ms
106,212 KB
testcase_15 AC 134 ms
105,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda:sys.stdin.readline().rstrip()
def kadomatsu(a):
	return (a[1]>a[0] and a[1]>a[2] and a[0]!=a[2]) or (a[1]<a[0] and a[1]<a[2] and a[0]!=a[2])
def solve():
	N=int(input())
	A=list(map(int,input().split()))
	ans=0
	for i in range(3):
		dp=[0 for i in range(N)]
		for j in range(2,N):
			dp[j]=dp[j-1]
			if kadomatsu(A[j-2:j+1]):
				dp[j]=max(dp[j],dp[j-3]+A[j-2])
		ans=max(ans,dp[N-1])
		A=A[1:]+[A[0]]
	print(ans)
T=int(input())
for i in range(T):
	solve()
0