結果
| 問題 | 
                            No.1827 最長部分スーパーリッチ門松列列
                             | 
                    
| コンテスト | |
| ユーザー | 
                             kozy
                         | 
                    
| 提出日時 | 2022-01-28 23:09:47 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 480 ms / 2,000 ms | 
| コード長 | 636 bytes | 
| コンパイル時間 | 366 ms | 
| コンパイル使用メモリ | 82,304 KB | 
| 実行使用メモリ | 258,160 KB | 
| 最終ジャッジ日時 | 2024-12-30 11:09:49 | 
| 合計ジャッジ時間 | 8,693 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 24 | 
ソースコード
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)
            
            
            
        
            
kozy