結果

問題 No.929 よくあるボールを移動するやつ
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2019-12-06 13:17:42
言語 Ruby
(3.3.0)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 246 bytes
コンパイル時間 57 ms
コンパイル使用メモリ 11,524 KB
実行使用メモリ 24,448 KB
最終ジャッジ日時 2023-08-24 19:51:24
合計ジャッジ時間 2,892 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
15,264 KB
testcase_01 AC 79 ms
15,132 KB
testcase_02 AC 78 ms
15,128 KB
testcase_03 AC 78 ms
15,028 KB
testcase_04 AC 78 ms
15,164 KB
testcase_05 AC 79 ms
15,308 KB
testcase_06 AC 79 ms
15,192 KB
testcase_07 AC 123 ms
19,000 KB
testcase_08 AC 191 ms
24,448 KB
testcase_09 AC 191 ms
24,304 KB
testcase_10 AC 151 ms
22,200 KB
testcase_11 AC 150 ms
22,092 KB
testcase_12 AC 153 ms
22,436 KB
testcase_13 AC 144 ms
22,172 KB
testcase_14 AC 151 ms
22,060 KB
testcase_15 AC 146 ms
22,060 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
B = gets.split.map(&:to_i)
S = Array.new(N + 1, 0)
B.each_with_index do |b,i|
  S[i + 1] = S[i] + b
end

t = 0
(1 .. N).inject(0) do |m, n|
  m_ = S[m] >= n ? m : (m .. N).find{|m_| S[m_] >= n }
  t += (n - m_).abs
  m_
end

puts t
0