結果

問題 No.929 よくあるボールを移動するやつ
ユーザー DrDrpilotDrDrpilot
提出日時 2022-02-07 16:07:46
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 570 bytes
コンパイル時間 322 ms
コンパイル使用メモリ 10,700 KB
実行使用メモリ 17,164 KB
最終ジャッジ日時 2023-09-03 20:16:42
合計ジャッジ時間 2,739 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,600 KB
testcase_01 AC 16 ms
8,576 KB
testcase_02 AC 16 ms
8,496 KB
testcase_03 AC 16 ms
8,448 KB
testcase_04 AC 16 ms
8,464 KB
testcase_05 AC 16 ms
8,556 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 106 ms
17,164 KB
testcase_14 AC 106 ms
13,028 KB
testcase_15 AC 106 ms
13,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
n=int(input())
b=list(map(int,input().split()))
ans=0
q=deque()
for i in range(n):
    if b[i]==0:
        q.append(i)
    else:
        num=b[i]-1
        while num>0 and q:
            out=q.popleft()
            ans+=i-out
            num-=1
            b[i]-=1
            b[out]+=1
b=b[::-1]
p=deque()
for i in range(n):
    if b[i]==0:
        p.append(i)
    else:
        num=b[i]-1
        while num>0 and q:
            out=p.popleft()
            ans+=i-out
            num-=1
            b[i]-=1
            b[out]+=1
print(ans)
0