結果

問題 No.2518 Adjacent Larger
ユーザー lloyzlloyz
提出日時 2023-10-28 21:20:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,224 bytes
コンパイル時間 192 ms
コンパイル使用メモリ 81,868 KB
実行使用メモリ 103,084 KB
最終ジャッジ日時 2023-10-28 21:20:11
合計ジャッジ時間 4,408 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,604 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 115 ms
76,496 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 57 ms
70,328 KB
testcase_12 AC 55 ms
72,372 KB
testcase_13 AC 57 ms
72,712 KB
testcase_14 AC 52 ms
70,328 KB
testcase_15 AC 52 ms
72,372 KB
testcase_16 AC 79 ms
101,424 KB
testcase_17 AC 65 ms
85,476 KB
testcase_18 AC 65 ms
85,564 KB
testcase_19 AC 62 ms
81,028 KB
testcase_20 AC 70 ms
90,644 KB
testcase_21 AC 74 ms
100,572 KB
testcase_22 AC 75 ms
100,572 KB
testcase_23 AC 82 ms
101,532 KB
testcase_24 AC 77 ms
101,264 KB
testcase_25 AC 86 ms
102,308 KB
testcase_26 AC 78 ms
102,324 KB
testcase_27 AC 76 ms
103,084 KB
testcase_28 AC 77 ms
101,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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