結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー sangonanasangonana
提出日時 2021-01-29 22:02:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 460 bytes
コンパイル時間 149 ms
コンパイル使用メモリ 10,896 KB
実行使用メモリ 31,332 KB
最終ジャッジ日時 2023-09-09 15:25:09
合計ジャッジ時間 5,050 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
7,972 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 339 ms
31,304 KB
testcase_06 AC 329 ms
31,312 KB
testcase_07 AC 257 ms
31,260 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def kadomatsu(x):
	if (x[2]>x[1] and x[0]>x[1]) or (x[2]<x[1] and x[0]<x[1]) and len(set(x))==3:
		return 1
	return 0 
t=int(input())
for _ in range(t):
	n=int(input())
	a=list(map(int,input().split()))
	a.append(a[0])
	a.append(a[1])
	ok=[0]*n
	for i in range(n):
		if kadomatsu(a[i:i+3]):
			ok[i]=1
	dp=[0]*(n+1)
	for i in range(n):
		if ok[i]==1:
			if i-3>=0:
				dp[i+1]=dp[i-2]+a[i]
			else:
				dp[i+1]=a[i]
		dp[i+1]=max(dp[i+1],dp[i])
	print(max(dp))
0