結果

問題 No.2518 Adjacent Larger
ユーザー MasKoaTSMasKoaTS
提出日時 2023-09-20 13:52:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 833 bytes
コンパイル時間 133 ms
コンパイル使用メモリ 81,852 KB
実行使用メモリ 101,684 KB
最終ジャッジ日時 2023-10-25 16:29:48
合計ジャッジ時間 3,569 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,264 KB
testcase_01 AC 147 ms
76,820 KB
testcase_02 AC 143 ms
76,892 KB
testcase_03 AC 129 ms
76,828 KB
testcase_04 AC 122 ms
76,828 KB
testcase_05 AC 150 ms
77,684 KB
testcase_06 AC 77 ms
75,704 KB
testcase_07 AC 76 ms
75,704 KB
testcase_08 AC 77 ms
75,716 KB
testcase_09 AC 75 ms
75,712 KB
testcase_10 AC 75 ms
75,712 KB
testcase_11 AC 56 ms
72,244 KB
testcase_12 AC 59 ms
73,304 KB
testcase_13 AC 56 ms
72,232 KB
testcase_14 AC 58 ms
72,252 KB
testcase_15 AC 56 ms
72,232 KB
testcase_16 AC 84 ms
101,404 KB
testcase_17 AC 68 ms
85,404 KB
testcase_18 AC 67 ms
85,432 KB
testcase_19 AC 64 ms
83,328 KB
testcase_20 AC 74 ms
92,088 KB
testcase_21 AC 80 ms
99,376 KB
testcase_22 AC 80 ms
99,376 KB
testcase_23 AC 88 ms
101,684 KB
testcase_24 AC 76 ms
99,216 KB
testcase_25 AC 78 ms
99,384 KB
testcase_26 AC 77 ms
99,384 KB
testcase_27 AC 79 ms
101,440 KB
testcase_28 AC 80 ms
101,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

for _ in [0] * int(input()):
    n = int(input())
    a = list(map(int, input().split()))
    if(2 not in a):
        print("No")
        continue
    dirs = [0] * n
    start = a.index(2)
    for i in range(n):
        k = (start + i) % n
        l = (k - 1) % n
        if(a[k] == 2):
            dirs[k], dirs[l] = 1, 0
        elif(a[k] == 0):
            dirs[k], dirs[l] = 0, 1
        else:
            dirs[k] = dirs[l]
    for i in range(n):
        j = (i - 1) % n
        if(a[i] == 2 and (dirs[i], dirs[j]) != (1, 0)):
            print("No")
            break
        elif(a[i] == 0 and (dirs[i], dirs[j]) != (0, 1)):
            print("No")
            break
        elif(a[i] == 1 and dirs[i] != dirs[j]):
            print("No")
            break
    else:
        print("Yes")
0