結果

問題 No.2518 Adjacent Larger
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2023-10-27 22:21:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,619 ms / 2,000 ms
コード長 760 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 81,552 KB
実行使用メモリ 109,428 KB
最終ジャッジ日時 2023-10-27 22:22:02
合計ジャッジ時間 18,523 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,408 KB
testcase_01 AC 311 ms
79,264 KB
testcase_02 AC 346 ms
78,984 KB
testcase_03 AC 350 ms
78,792 KB
testcase_04 AC 315 ms
78,832 KB
testcase_05 AC 339 ms
78,676 KB
testcase_06 AC 260 ms
77,424 KB
testcase_07 AC 275 ms
77,556 KB
testcase_08 AC 263 ms
77,456 KB
testcase_09 AC 268 ms
77,304 KB
testcase_10 AC 266 ms
77,276 KB
testcase_11 AC 227 ms
76,680 KB
testcase_12 AC 255 ms
77,308 KB
testcase_13 AC 247 ms
77,228 KB
testcase_14 AC 211 ms
77,408 KB
testcase_15 AC 230 ms
77,888 KB
testcase_16 AC 1,619 ms
106,800 KB
testcase_17 AC 869 ms
93,612 KB
testcase_18 AC 890 ms
93,988 KB
testcase_19 AC 748 ms
91,180 KB
testcase_20 AC 1,097 ms
98,196 KB
testcase_21 AC 176 ms
105,144 KB
testcase_22 AC 169 ms
105,144 KB
testcase_23 AC 1,572 ms
107,344 KB
testcase_24 AC 1,342 ms
106,424 KB
testcase_25 AC 1,371 ms
106,472 KB
testcase_26 AC 1,421 ms
106,472 KB
testcase_27 AC 324 ms
105,408 KB
testcase_28 AC 1,455 ms
109,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop,heappush

def solve():
    n = int(input())
    A = list(map(int,input().split()))
    use = [0]*n
    h = []
    for i,a in enumerate(A):
        heappush(h,[a,i])

    while h:
        c,ind = heappop(h)
        if A[ind]!= c:
            continue
        if A[ind]:
            return "No"

        use[ind] = 1
        ni = (ind+1)%n
        if use[ni] == 0:
            A[ni] -= 1
            if A[ni] < 0:
                return "No"
            heappush(h,[A[ni],ni])

        ni = (ind-1)%n
        if use[ni] == 0:
            A[ni] -= 1
            if A[ni] < 0:
                return "No"
            heappush(h,[A[ni],ni])

    return "Yes" if sum(A) == 0 else "No"

t = int(input())
for _ in range(t):
    print(solve())
0