結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー 👑 timitimi
提出日時 2021-03-05 17:05:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,526 ms / 2,000 ms
コード長 904 bytes
コンパイル時間 345 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 55,668 KB
最終ジャッジ日時 2024-04-16 04:33:44
合計ジャッジ時間 15,524 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
11,008 KB
testcase_01 AC 31 ms
11,008 KB
testcase_02 AC 434 ms
11,136 KB
testcase_03 AC 121 ms
11,008 KB
testcase_04 AC 217 ms
11,008 KB
testcase_05 AC 1,496 ms
45,096 KB
testcase_06 AC 1,473 ms
45,044 KB
testcase_07 AC 332 ms
34,280 KB
testcase_08 AC 1,526 ms
55,668 KB
testcase_09 AC 1,181 ms
35,448 KB
testcase_10 AC 1,168 ms
35,488 KB
testcase_11 AC 1,183 ms
35,488 KB
testcase_12 AC 1,164 ms
35,600 KB
testcase_13 AC 1,169 ms
35,496 KB
testcase_14 AC 1,160 ms
35,440 KB
testcase_15 AC 1,150 ms
35,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

T=int(input())
for i in range(T):
  N=int(input())
  A=list(map(int, input().split()))
  A=A+A
  B=A[1:]+A[:1]
  C=A[2:]+A[:2]
  a,b,c=0,0,0
  DA=[0]*(N+1)
  DB=[0]*(N+1)
  DC=[0]*(N+1)
  for j in range(3,N+1):
    DA[j]=DA[j-1]
    if A[j-1]!=A[j-2] and A[j-2]!=A[j-3] and A[j-1]!=A[j-3]:
      if min(A[j-1],A[j-2],A[j-3])==A[j-2] or max(A[j-1],A[j-2],A[j-3])==A[j-2]:
        DA[j]=max(DA[j],DA[j-3]+A[j-3])
  for j in range(3,N+1):
    DB[j]=DB[j-1]
    if B[j-1]!=B[j-2] and B[j-2]!=B[j-3] and B[j-1]!=B[j-3]:
      if min(B[j-1],B[j-2],B[j-3])==B[j-2] or max(B[j-1],B[j-2],B[j-3])==B[j-2]:
        DB[j]=max(DB[j],DB[j-3]+B[j-3])
  for j in range(3,N+1):
    DC[j]=DC[j-1]
    if C[j-1]!=C[j-2] and C[j-2]!=C[j-3] and C[j-1]!=C[j-3]:
      if min(C[j-1],C[j-2],C[j-3])==C[j-2] or max(C[j-1],C[j-2],C[j-3])==C[j-2]:
        DC[j]=max(DC[j],DC[j-3]+C[j-3])
        
  print(max(DA[-1],DB[-1],DC[-1]))
0