結果
| 問題 | 
                            No.2518 Adjacent Larger
                             | 
                    
| コンテスト | |
| ユーザー | 
                             sasa8uyauya
                         | 
                    
| 提出日時 | 2023-10-27 21:46:52 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 240 ms / 2,000 ms | 
| コード長 | 587 bytes | 
| コンパイル時間 | 173 ms | 
| コンパイル使用メモリ | 82,388 KB | 
| 実行使用メモリ | 108,832 KB | 
| 最終ジャッジ日時 | 2024-09-25 13:52:16 | 
| 合計ジャッジ時間 | 4,312 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 28 | 
ソースコード
t=int(input())
for _ in range(t):
  n=int(input())
  a=list(map(int,input().split()))
  if (0 not in a) or (2 not in a):
    print("No")
    continue
  i=0
  while a[i]!=0:
    i+=1
  a=a[i:]+a[:i]
  c=[""]*(n+1)
  c[0]=">"
  c[-1]="<"
  f=1
  for i in range(1,n):
    if a[i]==0:
      c[i]=">"
      if c[i-1]!="<" and f:
        print("No")
        f=0
    if a[i]==1:
      if c[i-1]=="<":
        c[i]="<"
      if c[i-1]==">":
        c[i]=">"
    if a[i]==2:
      c[i]="<"
      if c[i-1]!=">" and f:
        print("No")
        f=0
  if f:
    print(["No","Yes"][c[-1]==c[n-1]])
            
            
            
        
            
sasa8uyauya