結果
| 問題 | 
                            No.2518 Adjacent Larger
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2023-10-28 09:14:25 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 958 bytes | 
| コンパイル時間 | 311 ms | 
| コンパイル使用メモリ | 82,292 KB | 
| 実行使用メモリ | 117,376 KB | 
| 最終ジャッジ日時 | 2024-09-25 16:12:49 | 
| 合計ジャッジ時間 | 6,815 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 19 WA * 9 | 
ソースコード
import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random
#sys.setrecursionlimit(10**9)
#sys.set_int_max_str_digits(0)
#alist = []
#s = input()
t = int(input())
for _ in range(t):
    n = int(input())
    alist = list(map(int,input().split()))
    if sum(alist) != n:
        print('No')
        continue
    c = 0
    for i in range(n):
        if alist[i] == 2:
            if alist[i-1] == 2 or alist[(i+1)%n] == 2:
                print('No')
                c = 1
                break
        if alist[i] == 1:
            if alist[i-1] == 2 and alist[(i+1)%n] == 2:
                print('No')
                c = 1
                break
        if alist[i] == 0:
            if alist[i-1] == 0 or alist[(i+1)%n] == 0:
                print('No')
                c = 1
                break
    if alist.count(2) == 0 or alist.count(0) == 0:
        print('No')
        c = 1
    if not c:
        print('Yes')