結果

問題 No.2518 Adjacent Larger
コンテスト
ユーザー ntuda
提出日時 2023-12-21 23:33:47
言語 PyPy3
(7.3.23 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 161 ms / 2,000 ms
+ 507µs
コード長 669 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 234 ms
コンパイル使用メモリ 95,828 KB
実行使用メモリ 111,524 KB
最終ジャッジ日時 2026-09-05 06:06:40
合計ジャッジ時間 4,836 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

for _ in range(int(input())):
    N = int(input())
    A = list(map(int, input().split()))
    if sum(A) != N:
        print("No")
        continue
    if 0 not in A:
        print("No")
        continue
    j = A.index(0)
    f = 0
    ans = True
    for i in range(1, N + 1):
        if f == 0:
            if A[(i + j) % N] == 0:
                ans = False
                break
            if A[(i + j) % N] == 2:
                f = 2
        elif f == 2:
            if A[(i + j) % N] == 2:
                ans = False
                break
            if A[(i + j) % N] == 0:
                f = 0
    if ans:
        print("Yes")
    else:
        print("No")
0