結果

問題 No.2518 Adjacent Larger
ユーザー lloyzlloyz
提出日時 2023-10-28 01:57:04
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,312 bytes
コンパイル時間 332 ms
コンパイル使用メモリ 81,804 KB
実行使用メモリ 108,072 KB
最終ジャッジ日時 2023-10-28 01:57:08
合計ジャッジ時間 4,694 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,268 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 55 ms
72,164 KB
testcase_12 AC 55 ms
72,376 KB
testcase_13 AC 91 ms
75,252 KB
testcase_14 AC 54 ms
72,180 KB
testcase_15 AC 55 ms
72,164 KB
testcase_16 AC 86 ms
105,696 KB
testcase_17 AC 67 ms
86,164 KB
testcase_18 AC 65 ms
86,128 KB
testcase_19 AC 64 ms
82,156 KB
testcase_20 AC 72 ms
92,536 KB
testcase_21 AC 75 ms
101,808 KB
testcase_22 AC 76 ms
101,808 KB
testcase_23 AC 86 ms
108,072 KB
testcase_24 AC 80 ms
103,856 KB
testcase_25 AC 80 ms
104,252 KB
testcase_26 AC 80 ms
104,252 KB
testcase_27 AC 79 ms
104,308 KB
testcase_28 AC 81 ms
105,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

for _ in range(int(input())):
    n = int(input())
    A = list(map(int, input().split()))
    if n == 2:
        if A == [1, 0] or A == [0, 1]:
            print("Yes")
        else:
            print("No")
    else:
        zero = False
        two = False
        f = -1
        for i in range(n):
            if A[i] == 2:
                f = i
                break
        if f == -1:
            print("No")
            continue
        A = A[f:] + A[:f]
        A += A
        idx = 0
        flag = True
        while True:
            if A[idx] == 2:
                zero = False
                if two:
                    flag = False
                    break
                else:
                    two = True
            elif A[idx] == 1:
                zero = False
            elif A[idx] == 0:
                if not two:
                    flag = False
                    break
                two = False
                if zero:
                    flag = False
                    break
                else:
                    zero = True
                    if idx >= n:
                        break
            idx += 1
            if idx == 2 * n:
                flag = False
                break
        if flag:
            print("Yes")
        else:
            print("No")
0