結果

問題 No.929 よくあるボールを移動するやつ
ユーザー O2MTO2MT
提出日時 2020-12-08 15:48:16
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 405 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 81,896 KB
実行使用メモリ 94,964 KB
最終ジャッジ日時 2023-10-17 17:17:33
合計ジャッジ時間 4,300 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,624 KB
testcase_01 AC 37 ms
53,624 KB
testcase_02 AC 37 ms
53,624 KB
testcase_03 AC 38 ms
53,624 KB
testcase_04 AC 39 ms
53,624 KB
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 AC 137 ms
94,616 KB
testcase_14 AC 137 ms
94,616 KB
testcase_15 AC 139 ms
94,616 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)
    else:
        heappush(stock,(i,B[i]))
while zero != [] and stock != []:
    z = heappop(zero)
    s,i = heappop(stock)
    if i == 1:
        heappush(zero,s)
    else:
        heappush(stock,(s,i-1))
    count += abs(z-s)
print(count)
0