結果

問題 No.2518 Adjacent Larger
ユーザー MasKoaTSMasKoaTS
提出日時 2023-09-19 23:01:57
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,086 bytes
コンパイル時間 158 ms
コンパイル使用メモリ 81,508 KB
実行使用メモリ 143,080 KB
最終ジャッジ日時 2023-10-25 16:29:44
合計ジャッジ時間 5,690 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 216 ms
132,700 KB
testcase_17 AC 130 ms
97,544 KB
testcase_18 AC 155 ms
114,800 KB
testcase_19 AC 123 ms
97,584 KB
testcase_20 AC 159 ms
112,308 KB
testcase_21 AC 220 ms
137,556 KB
testcase_22 AC 223 ms
137,924 KB
testcase_23 AC 219 ms
133,824 KB
testcase_24 AC 185 ms
142,252 KB
testcase_25 AC 185 ms
142,132 KB
testcase_26 AC 181 ms
143,080 KB
testcase_27 WA -
testcase_28 AC 200 ms
131,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

for _ in [0] * int(input()):
    n = int(input())
    a = list(map(int, input().split()))
    graph = [set([]) for _ in [0] * n]
    stk = list((x, -1) for x in range(n) if(a[x] == 2))
    st = set(stk)
    while(stk):
        v, lv = stk.pop()
        pv, nv = (v - 1) % n, (v + 1) % n
        if(a[v] == 2):
            graph[v].add(pv)
            graph[v].add(nv)
            if(pv not in st):
                st.add(pv)
                stk.append((pv, v))
            if(nv not in st):
                st.add(nv)
                stk.append((nv, v))
        elif(a[v] == 1):
            if(pv != lv):
                graph[v].add(pv)
                if(pv not in st):
                    st.add(pv)
                    stk.append((pv, v))
            else:
                graph[v].add(nv)
                if(nv not in st):
                    st.add(nv)
                    stk.append((nv, v))
    for v, c in enumerate(a):
        if(len(graph[v]) == c):
            continue
        print("No")
        break
    else:
        print("Yes")
0