結果

問題 No.2518 Adjacent Larger
ユーザー atcoder8atcoder8
提出日時 2023-10-28 00:18:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 169 ms / 2,000 ms
コード長 846 bytes
コンパイル時間 1,310 ms
コンパイル使用メモリ 81,668 KB
実行使用メモリ 102,932 KB
最終ジャッジ日時 2023-10-28 00:18:42
合計ジャッジ時間 4,706 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
53,496 KB
testcase_01 AC 147 ms
77,032 KB
testcase_02 AC 153 ms
77,068 KB
testcase_03 AC 154 ms
77,072 KB
testcase_04 AC 151 ms
76,784 KB
testcase_05 AC 169 ms
77,068 KB
testcase_06 AC 85 ms
76,040 KB
testcase_07 AC 98 ms
76,056 KB
testcase_08 AC 84 ms
76,056 KB
testcase_09 AC 81 ms
76,044 KB
testcase_10 AC 83 ms
76,044 KB
testcase_11 AC 47 ms
70,060 KB
testcase_12 AC 47 ms
72,108 KB
testcase_13 AC 48 ms
70,200 KB
testcase_14 AC 46 ms
70,060 KB
testcase_15 AC 45 ms
70,060 KB
testcase_16 AC 83 ms
102,916 KB
testcase_17 AC 63 ms
84,608 KB
testcase_18 AC 61 ms
84,636 KB
testcase_19 AC 57 ms
82,664 KB
testcase_20 AC 64 ms
91,128 KB
testcase_21 AC 69 ms
95,760 KB
testcase_22 AC 66 ms
95,760 KB
testcase_23 AC 87 ms
100,568 KB
testcase_24 AC 69 ms
95,880 KB
testcase_25 AC 69 ms
98,048 KB
testcase_26 AC 75 ms
100,116 KB
testcase_27 AC 70 ms
98,124 KB
testcase_28 AC 85 ms
102,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(aa: list[int]):
    n = len(aa)

    zero_num = aa.count(0)
    two_num = aa.count(2)

    if (
        zero_num == 0
        or zero_num > n // 2
        or two_num == 0
        or two_num > n // 2
        or zero_num != two_num
    ):
        return False

    start = aa.index(0)
    inc = False
    for i in range(1, n):
        cur = (start + i) % n
        if inc:
            if aa[cur] == 2:
                return False

            if aa[cur] == 0:
                inc = False
        else:
            if aa[cur] == 0:
                return False

            if aa[cur] == 2:
                inc = True

    return True


def main():
    t = int(input())
    for _ in range(t):
        input()
        aa = list(map(int, input().split()))
        print("Yes" if solve(aa) else "No")


if __name__ == "__main__":
    main()
0