結果

問題 No.2518 Adjacent Larger
ユーザー flygonflygon
提出日時 2023-10-27 21:48:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 170 ms / 2,000 ms
コード長 867 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 81,768 KB
実行使用メモリ 147,796 KB
最終ジャッジ日時 2023-10-27 21:48:17
合計ジャッジ時間 4,640 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
55,692 KB
testcase_01 AC 126 ms
76,772 KB
testcase_02 AC 124 ms
76,780 KB
testcase_03 AC 132 ms
76,796 KB
testcase_04 AC 127 ms
76,788 KB
testcase_05 AC 147 ms
76,772 KB
testcase_06 AC 93 ms
76,396 KB
testcase_07 AC 93 ms
76,392 KB
testcase_08 AC 96 ms
76,392 KB
testcase_09 AC 94 ms
76,392 KB
testcase_10 AC 93 ms
76,392 KB
testcase_11 AC 76 ms
75,904 KB
testcase_12 AC 78 ms
75,956 KB
testcase_13 AC 77 ms
75,936 KB
testcase_14 AC 76 ms
75,896 KB
testcase_15 AC 79 ms
75,940 KB
testcase_16 AC 149 ms
115,408 KB
testcase_17 AC 104 ms
99,296 KB
testcase_18 AC 105 ms
99,336 KB
testcase_19 AC 125 ms
98,692 KB
testcase_20 AC 111 ms
102,464 KB
testcase_21 AC 156 ms
113,012 KB
testcase_22 AC 155 ms
113,504 KB
testcase_23 AC 147 ms
116,472 KB
testcase_24 AC 125 ms
147,796 KB
testcase_25 AC 113 ms
126,192 KB
testcase_26 AC 118 ms
133,316 KB
testcase_27 AC 145 ms
119,460 KB
testcase_28 AC 170 ms
119,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline
from collections import defaultdict, deque, Counter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
from math import gcd

def sol():
    n = int(input())
    a = list(map(int,input().split()))
    a = a+a
    ok = 1
    for i in range(2):
        lr = [[]]
        for i in range(2*n):
            if a[i] == 0:
                lr.append([])
            else:
                lr[-1].append(a[i])
        if len(lr) == 1:
            ok = 0
        for i in range(len(lr)):
            if lr[i].count(2) >= 2:
                ok = 0
        for i in range(2*n):
            if a[i] == 0:
                a[i] = 2
            elif a[i] == 2:
                a[i] = 0
    print('Yes') if ok else print('No')
    return 


T = int(input())
for i in range(T):
    sol()
0