結果

問題 No.2518 Adjacent Larger
ユーザー 👑 rin204
提出日時 2023-10-27 21:36:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 158 ms / 2,000 ms
コード長 512 bytes
コンパイル時間 258 ms
コンパイル使用メモリ 82,448 KB
実行使用メモリ 97,712 KB
最終ジャッジ日時 2024-09-25 13:41:04
合計ジャッジ時間 3,623 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve():
    n = int(input())
    A = list(map(int, input().split()))
    if sum(A) != n or 0 not in A:
        return False

    for b in range(2):
        x = b
        ok = True
        for a in A:
            x = a - (1 - x)
            if x < 0 or 2 <= x:
                ok = False
                break

        if x != b:
            ok = False
        if ok:
            return True
    return False


for _ in range(int(input())):
    if solve():
        print("Yes")
    else:
        print("No")
0