結果

問題 No.929 よくあるボールを移動するやつ
ユーザー MineMine
提出日時 2020-09-03 12:49:53
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
WA  
実行時間 -
コード長 570 bytes
コンパイル時間 1,175 ms
コンパイル使用メモリ 10,896 KB
実行使用メモリ 10,340 KB
最終ジャッジ日時 2023-08-15 02:06:08
合計ジャッジ時間 3,574 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,828 KB
testcase_01 AC 16 ms
7,772 KB
testcase_02 AC 16 ms
7,820 KB
testcase_03 AC 15 ms
7,868 KB
testcase_04 AC 16 ms
7,880 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
10,084 KB
testcase_14 AC 135 ms
10,064 KB
testcase_15 AC 138 ms
10,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
b = list(map(int, input().split()))

have = []
ans = 0
for i in range(n):
    if b[i] > 1:
        have.append((i, b[i]))
    if b[i] == 0 and have != []:
        g, p = have.pop()
        b[i] += 1
        b[g] -= 1
        ans += i-g
        if p-1 > 1:
            have.append((g, p-1))

have = []
for i in range(n)[::-1]:
    if b[i] > 1:
        have.append((i, b[i]))
    if b[i] == 0 and have != []:
        g, p = have.pop()
        b[i] += 1
        b[g] -= 1
        ans += g-i
        if p-1 > 1:
            have.append((g, p-1))

print(ans)
0