結果

問題 No.929 よくあるボールを移動するやつ
ユーザー ttr
提出日時 2020-02-02 19:46:08
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 557 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 12,752 KB
最終ジャッジ日時 2024-09-18 21:22:04
合計ジャッジ時間 2,028 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 5 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
B = [int(b) for b in input().split()]

ans = 0
ball = 0
cnt = 0
for i in range(N):
    if B[i] == 0 and ball == 0:
        cnt += 1
    elif B[i] == 0:
        ans += ball
        ball -= 1
    elif cnt > 0:
        if B[i] == 1:
            cnt += 1
            continue
        ball += B[i]-1
        while ball > 0 and cnt > 0:
            if B[i-cnt] > 0:
                cnt -= 1
                continue
            ans += cnt
            cnt -= 1
            ball -= 1
    else:
        ans += ball
        ball += B[i]-1

print(ans)
0