結果
問題 | No.1368 サイクルの中に眠る門松列 |
ユーザー |
![]() |
提出日時 | 2021-01-29 22:29:13 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 639 ms / 2,000 ms |
コード長 | 1,262 bytes |
コンパイル時間 | 87 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 30,968 KB |
最終ジャッジ日時 | 2024-06-27 08:46:37 |
合計ジャッジ時間 | 7,925 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 15 |
ソースコード
import sysfrom collections import defaultdict, Counter, dequefrom itertools import permutations, combinations, product, combinations_with_replacement, groupby, accumulateimport operator#from math import sqrt,isqrt#from bisect import bisect_left,bisect_right#from functools import lru_cache,reduce#import heapq#import numpy as np#import networkx as nx# from numba import njit, b1, i1, i4, i8, f8# numba例 @njit(i1(i4[:], i8[:, :]),cache=True) 引数i4配列、i8 2次元配列,戻り値i1def input(): return sys.stdin.readline().rstrip()def divceil(n, k): return 1+(n-1)//k # n/kの切り上げを返すdef check(a):return len(set(a)) == 3 and a[1] in [max(a), min(a)]def solve(n,a):value=[0]*nfor i in range(n):if check([a[i-2],a[i-1],a[i]]):value[i-2]=a[i-2]ans=0for i in range(3):dp=[0]*(n+1)for j in range(2,n):dp[j]=max(dp[j-1],dp[j-3]+value[j])ans=max(dp[-2],ans)num=value.pop(0)value.append(num)return ansdef main():mod = 10**9+7mod2 = 998244353t=int(input())for i in range(t):n=int(input())print(solve(n,list(map(int, input().split()))))if __name__ == '__main__':main()