結果
問題 | No.929 よくあるボールを移動するやつ |
ユーザー |
|
提出日時 | 2020-04-09 16:05:32 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 86 ms / 2,000 ms |
コード長 | 859 bytes |
コンパイル時間 | 335 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 15,428 KB |
最終ジャッジ日時 | 2024-09-13 12:06:00 |
合計ジャッジ時間 | 1,681 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 12 |
ソースコード
MOD = 10 ** 9 + 7INF = 10 ** 10import sysinput = sys.stdin.readlinesys.setrecursionlimit(100000000)dy = (-1,0,1,0)dx = (0,1,0,-1)from bisect import bisect_left,bisect_rightfrom collections import dequedef main():n = int(input())b = list(map(int,input().split()))ans = 0idx1 = deque()idx2 = deque()for i in range(n):if b[i] == 1:continueelif b[i] == 0:if len(idx2) > 0:p = idx2.popleft()ans += i - pelse:idx1.append(i)elif b[i] > 1:while len(idx1) and b[i] > 1:b[i] -= 1p = idx1.popleft()ans += i - pfor _ in range(b[i] - 1):idx2.append(i)print(ans)if __name__ =='__main__':main()