結果
問題 | No.1368 サイクルの中に眠る門松列 |
ユーザー | donuthole |
提出日時 | 2021-01-29 22:07:29 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 159 ms / 2,000 ms |
コード長 | 1,110 bytes |
コンパイル時間 | 154 ms |
コンパイル使用メモリ | 82,116 KB |
実行使用メモリ | 106,112 KB |
最終ジャッジ日時 | 2024-06-27 08:19:47 |
合計ジャッジ時間 | 3,151 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 15 |
ソースコード
import sys import math import collections import bisect # sys.setrecursionlimit(10000001) INF = 10 ** 20 # MOD = 10 ** 9 + 7 MOD = 998244353 def ni(): return int(sys.stdin.buffer.readline()) def ns(): return map(int, sys.stdin.buffer.readline().split()) def na(): return list(map(int, sys.stdin.buffer.readline().split())) def na1(): return list(map(lambda x: int(x)-1, sys.stdin.buffer.readline().split())) # ===CODE=== def main(): t = ni() for ti in range(t): n = ni() a = na() flg = [False]*n for i in range(n): nxt = (i+1) % n nnxt = (i+2) % n ta = [a[i], a[nxt], a[nnxt]] if len(set(ta)) == 3 and (ta[0] < ta[1] > ta[2] or ta[0] > ta[1] < ta[2]): flg[i] = True res = 0 for i in range(3): dp = [0]*(n+3) for j in range(i, n-2+i): if flg[j]: dp[j+3] = max(dp[j+3], dp[j]+a[j]) dp[j+1] = max(dp[j+1], dp[j]) res = max(res, max(dp)) print(res) if __name__ == '__main__': main()