結果
問題 | No.929 よくあるボールを移動するやつ |
ユーザー |
![]() |
提出日時 | 2020-09-16 09:33:35 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 140 ms / 2,000 ms |
コード長 | 488 bytes |
コンパイル時間 | 45 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 21,376 KB |
最終ジャッジ日時 | 2024-06-22 03:04:35 |
合計ジャッジ時間 | 2,374 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 12 |
コンパイルメッセージ
Syntax OK
ソースコード
N = gets.to_iB = gets.split.map(&:to_i)stock = []empty = []ans = 0B.each_with_index do |b, idx|if b == 0if stock.empty?empty << idxelsei, cnt = stock.popans += idx - icnt -= 1stock.push([i, cnt]) if cnt > 0endelsewhile empty.size > 0 && b > 0i = empty.popans += idx - ib -= 1endif b == 0empty.push(idx)elsif b >= 2stock.push([idx, b - 1])endendendputs ans