結果

問題 No.929 よくあるボールを移動するやつ
ユーザー ttrttr
提出日時 2020-02-02 19:46:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 557 bytes
コンパイル時間 86 ms
コンパイル使用メモリ 11,920 KB
実行使用メモリ 12,108 KB
最終ジャッジ日時 2023-10-19 01:24:25
合計ジャッジ時間 2,185 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,196 KB
testcase_01 AC 32 ms
10,196 KB
testcase_02 AC 31 ms
10,196 KB
testcase_03 AC 31 ms
10,196 KB
testcase_04 AC 30 ms
10,196 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 84 ms
12,108 KB
testcase_13 AC 85 ms
11,992 KB
testcase_14 AC 110 ms
11,992 KB
testcase_15 AC 98 ms
11,992 KB
権限があれば一括ダウンロードができます

ソースコード

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