結果

問題 No.929 よくあるボールを移動するやつ
ユーザー O2MTO2MT
提出日時 2020-12-08 16:12:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 285 ms / 2,000 ms
コード長 473 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 81,776 KB
実行使用メモリ 94,548 KB
最終ジャッジ日時 2023-10-17 17:19:13
合計ジャッジ時間 3,379 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,528 KB
testcase_01 AC 39 ms
53,528 KB
testcase_02 AC 39 ms
53,524 KB
testcase_03 AC 38 ms
53,528 KB
testcase_04 AC 38 ms
53,524 KB
testcase_05 AC 38 ms
53,528 KB
testcase_06 AC 41 ms
53,528 KB
testcase_07 AC 224 ms
80,304 KB
testcase_08 AC 285 ms
92,224 KB
testcase_09 AC 282 ms
92,260 KB
testcase_10 AC 251 ms
94,484 KB
testcase_11 AC 237 ms
94,544 KB
testcase_12 AC 247 ms
94,548 KB
testcase_13 AC 139 ms
94,536 KB
testcase_14 AC 137 ms
94,536 KB
testcase_15 AC 140 ms
94,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *
N = int(input())
B = list(map(int,input().split()))
zero = []
stock = []
count = 0
for i in range(N):
    if B[i] == 0:
        heappush(zero,i)
    elif B[i] == 1:
        pass
    else:
        heappush(stock,(i,B[i]))
while zero != [] and stock != []:
    z = heappop(zero)
    s,i = heappop(stock)
    if i > 1:
        heappush(stock,(s,i-1))
    else:
        s,i = heappop(stock)
        heappush(stock,(s,i-1))
    count += abs(z-s)
print(count)
0