結果

問題 No.609 Noelちゃんと星々
ユーザー cympfhcympfh
提出日時 2017-12-17 16:05:02
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 427 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 93,544 KB
最終ジャッジ日時 2024-05-09 10:24:19
合計ジャッジ時間 6,848 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:1: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

n = gets.to_i
ys = gets.chomp.split.map(&:to_i)
left = ys.min
right = ys.max

500.times do
  r1 = (left + left + right) / 3
  r2 = (left + right + right) / 3
  s1 = ys.map { |y| (y - r1).abs }.inject :+
  s2 = ys.map { |y| (y - r2).abs }.inject :+
  if s1 < s2
    right = r2
  else
    left = r1
  end
end

ans = 100000000000
(left..right).each do |r|
  s = ys.map { |y| (y - r).abs }.inject :+
  ans = [ans, s].min
end
p ans
0