結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー simansiman
提出日時 2022-08-05 13:21:12
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 520 bytes
コンパイル時間 56 ms
コンパイル使用メモリ 11,280 KB
実行使用メモリ 40,960 KB
最終ジャッジ日時 2023-10-13 12:13:16
合計ジャッジ時間 60,475 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
15,348 KB
testcase_01 AC 77 ms
15,252 KB
testcase_02 AC 80 ms
15,340 KB
testcase_03 AC 78 ms
15,300 KB
testcase_04 AC 78 ms
15,096 KB
testcase_05 AC 79 ms
15,172 KB
testcase_06 AC 81 ms
15,088 KB
testcase_07 AC 79 ms
15,124 KB
testcase_08 AC 80 ms
15,088 KB
testcase_09 AC 78 ms
15,080 KB
testcase_10 AC 79 ms
15,152 KB
testcase_11 AC 79 ms
15,132 KB
testcase_12 AC 78 ms
15,152 KB
testcase_13 AC 77 ms
15,144 KB
testcase_14 AC 81 ms
15,320 KB
testcase_15 AC 79 ms
15,100 KB
testcase_16 AC 80 ms
15,072 KB
testcase_17 AC 79 ms
15,232 KB
testcase_18 TLE -
testcase_19 TLE -
testcase_20 AC 1,230 ms
28,892 KB
testcase_21 AC 244 ms
16,368 KB
testcase_22 AC 1,329 ms
30,028 KB
testcase_23 AC 200 ms
15,640 KB
testcase_24 AC 1,708 ms
34,416 KB
testcase_25 AC 1,271 ms
29,280 KB
testcase_26 AC 508 ms
19,828 KB
testcase_27 AC 204 ms
16,364 KB
testcase_28 TLE -
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
testcase_32 TLE -
testcase_33 TLE -
testcase_34 TLE -
testcase_35 TLE -
testcase_36 TLE -
testcase_37 TLE -
testcase_38 TLE -
testcase_39 TLE -
testcase_40 TLE -
testcase_41 TLE -
testcase_42 TLE -
testcase_43 AC 80 ms
15,248 KB
testcase_44 AC 80 ms
15,204 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def ternary_search_tree(left, right)
  loop_cnt = 50

  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