結果
問題 | No.1368 サイクルの中に眠る門松列 |
ユーザー | GER_chen |
提出日時 | 2021-01-29 21:47:45 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,523 bytes |
コンパイル時間 | 169 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 108,032 KB |
最終ジャッジ日時 | 2024-06-27 08:01:50 |
合計ジャッジ時間 | 3,382 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
52,096 KB |
testcase_01 | AC | 41 ms
51,840 KB |
testcase_02 | AC | 215 ms
78,848 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 177 ms
107,904 KB |
testcase_06 | AC | 180 ms
107,776 KB |
testcase_07 | AC | 123 ms
108,032 KB |
testcase_08 | AC | 178 ms
107,776 KB |
testcase_09 | AC | 168 ms
105,856 KB |
testcase_10 | AC | 170 ms
106,240 KB |
testcase_11 | AC | 167 ms
106,496 KB |
testcase_12 | AC | 165 ms
105,856 KB |
testcase_13 | AC | 175 ms
106,624 KB |
testcase_14 | AC | 169 ms
106,112 KB |
testcase_15 | AC | 166 ms
106,368 KB |
ソースコード
import sys;input = lambda: sys.stdin.readline().rstrip() #import heapq #from collections import deque #import numpy as np #from collections import Counter as cnt #from collections import defaultdict as ddc #from math import factorial as fct #from math import gcd #from bisect import bisect_left as bsl #from bisect import bisect_right as bsr #from itertools import accumulate as acc #from itertools import combinations as cmb #from itertools import permutations as pmt #from itertools import product as prd #from functools import reduce as red #import sys #sys.setrecursionlimit(10**9) #再帰を多く使う(デフォルトは1000) for _ in range(int(input())): n = int(input()) A = list(map(int,input().split())) A += A[:2] K = [0]*n for i in range(n): S = A[i:i+3] if len(set(S)) == 3 and S[1] in {min(S), max(S)}: K[i] = S[0] DP0 = [0]*n DP0[0], DP0[1], DP0[2] = K[0], K[0], K[0] for i in range(3, n): DP0[i] = max(DP0[i-1], DP0[i-2], DP0[i-3]+K[i]) cand0 = DP0[-3] DP1 = [0]*n DP1[0], DP1[1], DP1[2] = 0, K[1], K[1] if n >3: DP1[3] = K[1] for i in range(4, n): DP1[i] = max(DP1[i-1], DP1[i-2], DP1[i-3]+K[i]) cand1 = DP1[-2] DP2 = [0]*n DP2[0], DP2[1], DP2[2] = 0, 0, K[2] if n > 3: DP2[3] = K[2] if n >4: DP2[4] = K[2] for i in range(5, n): DP2[i] = max(DP2[i-1], DP2[i-2], DP2[i-3]+K[i]) cand2 = DP2[-1] print(max(cand0, cand1, cand2))