結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー tamura2004tamura2004
提出日時 2021-01-22 20:33:52
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,816 ms / 2,000 ms
コード長 367 bytes
コンパイル時間 53 ms
コンパイル使用メモリ 11,576 KB
実行使用メモリ 40,940 KB
最終ジャッジ日時 2023-08-27 16:23:51
合計ジャッジ時間 47,948 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
15,256 KB
testcase_01 AC 73 ms
15,300 KB
testcase_02 AC 67 ms
15,316 KB
testcase_03 AC 70 ms
15,248 KB
testcase_04 AC 70 ms
15,128 KB
testcase_05 AC 71 ms
15,080 KB
testcase_06 AC 72 ms
15,200 KB
testcase_07 AC 68 ms
15,160 KB
testcase_08 AC 71 ms
15,152 KB
testcase_09 AC 72 ms
15,180 KB
testcase_10 AC 71 ms
15,380 KB
testcase_11 AC 76 ms
15,164 KB
testcase_12 AC 73 ms
15,308 KB
testcase_13 AC 70 ms
15,040 KB
testcase_14 AC 72 ms
15,168 KB
testcase_15 AC 69 ms
15,160 KB
testcase_16 AC 70 ms
15,152 KB
testcase_17 AC 72 ms
15,076 KB
testcase_18 AC 1,652 ms
39,288 KB
testcase_19 AC 1,624 ms
38,632 KB
testcase_20 AC 952 ms
28,688 KB
testcase_21 AC 200 ms
16,248 KB
testcase_22 AC 1,039 ms
29,840 KB
testcase_23 AC 167 ms
15,560 KB
testcase_24 AC 1,327 ms
34,512 KB
testcase_25 AC 1,006 ms
29,352 KB
testcase_26 AC 392 ms
19,896 KB
testcase_27 AC 160 ms
16,232 KB
testcase_28 AC 1,792 ms
40,940 KB
testcase_29 AC 1,816 ms
40,616 KB
testcase_30 AC 1,755 ms
40,748 KB
testcase_31 AC 1,802 ms
40,824 KB
testcase_32 AC 1,719 ms
40,832 KB
testcase_33 AC 1,768 ms
40,652 KB
testcase_34 AC 1,756 ms
40,740 KB
testcase_35 AC 1,780 ms
40,912 KB
testcase_36 AC 1,765 ms
40,720 KB
testcase_37 AC 1,725 ms
40,820 KB
testcase_38 AC 1,715 ms
40,924 KB
testcase_39 AC 1,723 ms
40,744 KB
testcase_40 AC 1,713 ms
40,636 KB
testcase_41 AC 1,671 ms
40,640 KB
testcase_42 AC 1,775 ms
40,728 KB
testcase_43 AC 70 ms
15,328 KB
testcase_44 AC 70 ms
15,160 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 = a.min
hi = a.max
while hi - lo > 2
  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