結果

問題 No.2518 Adjacent Larger
ユーザー miya145592miya145592
提出日時 2023-10-27 23:16:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 1,212 bytes
コンパイル時間 196 ms
コンパイル使用メモリ 81,644 KB
実行使用メモリ 102,032 KB
最終ジャッジ日時 2023-10-27 23:16:25
合計ジャッジ時間 3,814 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
53,416 KB
testcase_01 AC 109 ms
76,960 KB
testcase_02 AC 145 ms
76,864 KB
testcase_03 AC 112 ms
76,700 KB
testcase_04 AC 116 ms
76,876 KB
testcase_05 AC 107 ms
76,964 KB
testcase_06 AC 77 ms
76,004 KB
testcase_07 AC 72 ms
75,660 KB
testcase_08 AC 73 ms
75,692 KB
testcase_09 AC 74 ms
75,956 KB
testcase_10 AC 73 ms
75,868 KB
testcase_11 AC 49 ms
72,436 KB
testcase_12 AC 54 ms
73,744 KB
testcase_13 AC 50 ms
72,420 KB
testcase_14 AC 48 ms
72,428 KB
testcase_15 AC 64 ms
72,952 KB
testcase_16 AC 77 ms
101,604 KB
testcase_17 AC 61 ms
85,596 KB
testcase_18 AC 59 ms
85,628 KB
testcase_19 AC 58 ms
81,468 KB
testcase_20 AC 65 ms
90,220 KB
testcase_21 AC 64 ms
98,976 KB
testcase_22 AC 65 ms
98,976 KB
testcase_23 AC 77 ms
102,032 KB
testcase_24 AC 71 ms
99,420 KB
testcase_25 AC 74 ms
99,588 KB
testcase_26 AC 75 ms
101,652 KB
testcase_27 AC 73 ms
99,596 KB
testcase_28 AC 72 ms
99,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
    N = int(input())
    A = list(map(int, input().split()))
    j = -1
    for i in range(N):
        if A[i]==2:
            j = i
            break
    if j==-1:
        print("No")
        continue
    in_deg = [0 for _ in range(N)]
    flag = True
    for ii in range(N):
        i = (ii+j)%N
        pre = (i-1)%N
        nxt = (i+1)%N
        if A[i]==2:
            if in_deg[pre]+A[pre]>=2 or in_deg[nxt]+A[nxt]>=2:
                flag = False
                break
            in_deg[pre]+=1
            in_deg[nxt]+=1
        elif A[i]==1:
            if in_deg[pre]+A[pre]>=2:
                if in_deg[nxt]+A[nxt]>=2:
                    flag = False
                    break
                else:
                    in_deg[nxt]+=1
            else:
                in_deg[pre]+=1
    for i in range(N):
        if A[i]+in_deg[i]!=2:
            flag = False
            break

    if flag:
        flag = False
        for i in range(N):
            if A[i]!=1:
                flag = True
                break
        if flag:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
0