結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー tamura2004tamura2004
提出日時 2021-01-22 20:32:48
言語 Ruby
(3.3.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 388 bytes
コンパイル時間 716 ms
コンパイル使用メモリ 11,120 KB
実行使用メモリ 40,788 KB
最終ジャッジ日時 2023-08-27 16:22:43
合計ジャッジ時間 56,492 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,220 KB
testcase_01 AC 82 ms
15,080 KB
testcase_02 AC 82 ms
15,176 KB
testcase_03 AC 82 ms
15,172 KB
testcase_04 AC 83 ms
15,072 KB
testcase_05 AC 82 ms
15,040 KB
testcase_06 AC 81 ms
15,100 KB
testcase_07 AC 81 ms
15,096 KB
testcase_08 AC 81 ms
14,976 KB
testcase_09 AC 82 ms
15,096 KB
testcase_10 AC 81 ms
15,148 KB
testcase_11 AC 81 ms
15,284 KB
testcase_12 AC 81 ms
14,964 KB
testcase_13 AC 81 ms
15,332 KB
testcase_14 AC 82 ms
15,180 KB
testcase_15 AC 81 ms
15,152 KB
testcase_16 AC 81 ms
15,148 KB
testcase_17 AC 81 ms
15,044 KB
testcase_18 AC 1,891 ms
39,412 KB
testcase_19 AC 1,823 ms
38,616 KB
testcase_20 AC 1,091 ms
28,624 KB
testcase_21 AC 229 ms
16,416 KB
testcase_22 AC 1,173 ms
29,932 KB
testcase_23 AC 186 ms
15,624 KB
testcase_24 AC 1,451 ms
34,308 KB
testcase_25 AC 1,159 ms
29,524 KB
testcase_26 AC 445 ms
20,028 KB
testcase_27 AC 187 ms
16,104 KB
testcase_28 AC 1,978 ms
40,512 KB
testcase_29 AC 1,974 ms
40,736 KB
testcase_30 AC 1,932 ms
40,644 KB
testcase_31 AC 1,989 ms
40,664 KB
testcase_32 AC 1,882 ms
40,716 KB
testcase_33 AC 1,980 ms
40,496 KB
testcase_34 AC 1,965 ms
40,588 KB
testcase_35 TLE -
testcase_36 AC 1,924 ms
40,756 KB
testcase_37 AC 1,953 ms
40,624 KB
testcase_38 AC 1,872 ms
40,520 KB
testcase_39 AC 1,931 ms
40,788 KB
testcase_40 AC 1,982 ms
40,740 KB
testcase_41 AC 1,878 ms
40,480 KB
testcase_42 AC 1,891 ms
40,748 KB
testcase_43 AC 79 ms
15,016 KB
testcase_44 AC 80 ms
15,048 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n = gets.to_s.to_i
a = gets.to_s.split.map { |v| v.to_i }
b = gets.to_s.split.map { |v| v.to_i }
f = ->x { n.times.sum { |i| b[i] * (a[i] - x).abs } }

lo = -1000000
hi = 1000000
while hi - lo > 2
  # 40.times do
  left = (lo * 2 + hi) / 3
  right = (lo + hi * 2) / 3
  if f[left] < f[right]
    hi = right
  else
    lo = left
  end
end

x = (lo + hi) / 2
y = f[x]
puts [x, y].join(" ")
0