結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー simansiman
提出日時 2022-08-05 13:22:48
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 521 bytes
コンパイル時間 463 ms
コンパイル使用メモリ 11,160 KB
実行使用メモリ 40,864 KB
最終ジャッジ日時 2023-10-13 12:14:49
合計ジャッジ時間 52,764 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,080 KB
testcase_01 AC 83 ms
15,136 KB
testcase_02 AC 83 ms
15,216 KB
testcase_03 AC 83 ms
15,248 KB
testcase_04 AC 82 ms
15,272 KB
testcase_05 AC 82 ms
15,128 KB
testcase_06 AC 82 ms
15,236 KB
testcase_07 AC 82 ms
15,240 KB
testcase_08 AC 83 ms
15,316 KB
testcase_09 AC 83 ms
15,248 KB
testcase_10 AC 81 ms
15,084 KB
testcase_11 AC 83 ms
15,248 KB
testcase_12 AC 83 ms
15,088 KB
testcase_13 AC 80 ms
15,124 KB
testcase_14 AC 82 ms
15,172 KB
testcase_15 AC 81 ms
15,252 KB
testcase_16 AC 81 ms
15,248 KB
testcase_17 WA -
testcase_18 AC 1,778 ms
39,640 KB
testcase_19 AC 1,707 ms
38,544 KB
testcase_20 AC 1,018 ms
28,752 KB
testcase_21 AC 217 ms
16,292 KB
testcase_22 AC 1,107 ms
29,920 KB
testcase_23 AC 178 ms
15,876 KB
testcase_24 AC 1,407 ms
34,448 KB
testcase_25 AC 1,055 ms
29,460 KB
testcase_26 AC 434 ms
20,016 KB
testcase_27 AC 185 ms
16,344 KB
testcase_28 AC 1,850 ms
40,700 KB
testcase_29 AC 1,900 ms
40,700 KB
testcase_30 AC 1,847 ms
40,656 KB
testcase_31 AC 1,852 ms
40,584 KB
testcase_32 AC 1,853 ms
40,600 KB
testcase_33 AC 1,858 ms
40,784 KB
testcase_34 AC 1,842 ms
40,564 KB
testcase_35 AC 1,842 ms
40,680 KB
testcase_36 AC 1,845 ms
40,576 KB
testcase_37 AC 1,846 ms
40,864 KB
testcase_38 AC 1,836 ms
40,716 KB
testcase_39 AC 1,889 ms
40,744 KB
testcase_40 AC 1,841 ms
40,728 KB
testcase_41 AC 1,856 ms
40,752 KB
testcase_42 AC 1,844 ms
40,800 KB
testcase_43 AC 81 ms
15,252 KB
testcase_44 AC 80 ms
15,268 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def ternary_search_tree(left, right)
  loop_cnt = 40 

  loop_cnt.times do
    if yield((left * 2 + right) / 3) < yield((left + right * 2) / 3)
      right = (left + right * 2) / 3
    else
      left = (left * 2 + right) / 3
    end
  end

  (left + right) / 2
end

N = gets.to_i
A = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)

def f(x)
  sum = 0

  N.times do |i|
    sum += B[i] * (x - A[i]).abs
  end

  sum
end

res = ternary_search_tree(-1 * 10 ** 7, 10 ** 7) { |x| f(x) }

puts [res, f(res).to_i].join(' ')
0