結果

問題 No.929 よくあるボールを移動するやつ
ユーザー simansiman
提出日時 2020-09-16 09:31:16
言語 Ruby
(3.2.2)
結果
WA  
実行時間 -
コード長 491 bytes
コンパイル時間 636 ms
コンパイル使用メモリ 11,304 KB
実行使用メモリ 23,704 KB
最終ジャッジ日時 2023-09-04 03:22:39
合計ジャッジ時間 4,321 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
15,168 KB
testcase_01 AC 86 ms
15,232 KB
testcase_02 WA -
testcase_03 AC 87 ms
15,088 KB
testcase_04 AC 85 ms
15,236 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 152 ms
23,132 KB
testcase_11 AC 144 ms
21,464 KB
testcase_12 WA -
testcase_13 AC 157 ms
23,704 KB
testcase_14 AC 146 ms
22,280 KB
testcase_15 AC 151 ms
23,384 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
B = gets.split.map(&:to_i)

stock = []
empty = []
ans = 0

B.each_with_index do |b, idx|
  if b == 0
    if stock.empty?
      empty << idx
    else
      i, cnt = stock.pop

      ans += idx - i
      cnt -= 1

      stock.push([i, cnt]) if cnt > 0
    end
  else
    while empty.size > 0 && b > 0
      i = empty.pop
      ans += idx - i
      b -= 1
    end

    r = b - 1

    if r <= 0
      empty.push(idx)
    else
      stock.push([idx, r])
    end
  end
end

puts ans
0