結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,344 KB
testcase_01 AC 79 ms
15,136 KB
testcase_02 AC 80 ms
15,216 KB
testcase_03 AC 78 ms
15,168 KB
testcase_04 AC 78 ms
15,168 KB
testcase_05 AC 82 ms
15,212 KB
testcase_06 AC 78 ms
15,212 KB
testcase_07 AC 120 ms
17,676 KB
testcase_08 AC 183 ms
22,136 KB
testcase_09 AC 183 ms
22,052 KB
testcase_10 AC 201 ms
22,236 KB
testcase_11 AC 245 ms
22,148 KB
testcase_12 AC 140 ms
21,976 KB
testcase_13 AC 141 ms
22,172 KB
testcase_14 AC 242 ms
22,164 KB
testcase_15 AC 188 ms
21,972 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_ = (1 .. N).inject(0) do |t,n|
  if S[n] >= n
    t + S[n] - n
  else
    r = S.bsearch_index{|s| s >= n }
    t + r - n
  end
end
puts t_
0