結果

問題 No.929 よくあるボールを移動するやつ
ユーザー hedwig100hedwig100
提出日時 2020-04-09 16:05:32
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 859 bytes
コンパイル時間 113 ms
コンパイル使用メモリ 10,992 KB
実行使用メモリ 13,296 KB
最終ジャッジ日時 2023-10-11 13:20:53
合計ジャッジ時間 1,767 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,540 KB
testcase_01 AC 19 ms
8,744 KB
testcase_02 AC 19 ms
8,668 KB
testcase_03 AC 18 ms
8,708 KB
testcase_04 AC 19 ms
8,552 KB
testcase_05 AC 18 ms
8,544 KB
testcase_06 AC 19 ms
8,668 KB
testcase_07 AC 34 ms
9,412 KB
testcase_08 AC 55 ms
10,476 KB
testcase_09 AC 55 ms
10,364 KB
testcase_10 AC 60 ms
10,352 KB
testcase_11 AC 61 ms
10,408 KB
testcase_12 AC 55 ms
10,488 KB
testcase_13 AC 56 ms
10,548 KB
testcase_14 AC 67 ms
13,296 KB
testcase_15 AC 60 ms
11,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from bisect import bisect_left,bisect_right
from collections import deque

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

    ans = 0
    idx1 = deque()
    idx2 = deque()
    for i in range(n):
        if b[i] == 1:
            continue
        elif b[i] == 0:
            if len(idx2) > 0:
                p = idx2.popleft()
                ans += i - p 
            else:
                idx1.append(i)
        elif b[i] > 1:
            while len(idx1) and b[i] > 1:
                b[i] -= 1
                p = idx1.popleft()
                ans += i - p
            
            for _ in range(b[i] - 1):
                idx2.append(i)
    print(ans)

if __name__ =='__main__':
    main()  
0