結果

問題 No.1827 最長部分スーパーリッチ門松列列
ユーザー kozykozy
提出日時 2022-01-28 23:09:15
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,673 ms / 2,000 ms
コード長 636 bytes
コンパイル時間 437 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 78,468 KB
最終ジャッジ日時 2024-12-30 11:08:08
合計ジャッジ時間 26,365 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
for i in range(N):
  s=int(input())
  A=list(map(int,input().split()))
  A=[0]+A+[0]
  c=dict()
  for j in range(len(A)):
    c[A[j]]=j
  if c[s]==1 or c[s]==s:
    this=2
    ans=2
  else:
    this=3
    ans=3
  for j in range(s-1,0,-1):
    if (A[c[j]]>A[c[j]-1] and A[c[j]]>A[c[j]+1]):
      if c[j]==1 or c[j]==s:
        this+=1
      else:
        this+=2
    if (A[c[j]]<A[c[j]-1] and A[c[j]]<A[c[j]+1]):
      this-=2
    if A[c[j]-1]==0:
      if A[c[j]+1]>A[c[j]]:
        this-=1
    if A[c[j]+1]==0:
      if A[c[j]-1]>A[c[j]]:
        this-=1
    
    #print(this,"a")
    
    ans=max(ans,this)
  print(ans)
0