結果

問題 No.2518 Adjacent Larger
ユーザー rlangevinrlangevin
提出日時 2023-10-27 21:48:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 813 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 81,868 KB
実行使用メモリ 118,324 KB
最終ジャッジ日時 2023-10-27 21:49:02
合計ジャッジ時間 3,692 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,424 KB
testcase_01 AC 127 ms
76,976 KB
testcase_02 AC 137 ms
76,964 KB
testcase_03 AC 129 ms
76,976 KB
testcase_04 AC 136 ms
76,952 KB
testcase_05 AC 131 ms
76,688 KB
testcase_06 AC 73 ms
75,828 KB
testcase_07 AC 74 ms
75,824 KB
testcase_08 AC 74 ms
75,824 KB
testcase_09 AC 72 ms
75,828 KB
testcase_10 AC 74 ms
75,828 KB
testcase_11 AC 54 ms
72,436 KB
testcase_12 AC 55 ms
73,864 KB
testcase_13 AC 62 ms
75,464 KB
testcase_14 AC 54 ms
72,424 KB
testcase_15 AC 52 ms
72,416 KB
testcase_16 AC 87 ms
112,252 KB
testcase_17 AC 76 ms
91,044 KB
testcase_18 AC 67 ms
89,072 KB
testcase_19 AC 64 ms
85,624 KB
testcase_20 AC 76 ms
97,440 KB
testcase_21 AC 84 ms
110,100 KB
testcase_22 AC 83 ms
110,084 KB
testcase_23 AC 89 ms
112,356 KB
testcase_24 AC 72 ms
95,620 KB
testcase_25 AC 72 ms
97,768 KB
testcase_26 AC 72 ms
97,768 KB
testcase_27 AC 90 ms
118,324 KB
testcase_28 AC 92 ms
118,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

T = int(input())
for _ in range(T):
    N = int(input())
    B = list(map(int, input().split()))
    A = []
    for b in B:
        if b != 1:
            A.append(b)
    N = len(A)
    if 2 not in A or 0 not in A:
        print("No")
        continue
    A = [A[-1]] + A + [A[0]]
    flag = 1
    for i in range(1, N + 1):
        if A[i] == 2 and (A[i - 1] == 2 or A[i + 1] == 2):
            flag = 0
            break
        if A[i] != 0 and (A[i - 1] == 2 and A[i + 1] == 2):
            flag = 0
            break
        if A[i] == 0 and (A[i - 1] == 0 or A[i + 1] == 0):
            flag = 0
            break
        if A[i] != 2 and (A[i - 1] == 0 and A[i + 1] == 0):
            flag = 0
            break
        
    print("Yes") if flag else print("No") 
    
0