結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー 👑 obakyanobakyan
提出日時 2021-05-24 09:02:58
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 366 ms / 2,000 ms
コード長 639 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 5,376 KB
実行使用メモリ 30,080 KB
最終ジャッジ日時 2024-04-20 18:55:44
合計ジャッジ時間 18,172 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 334 ms
28,032 KB
testcase_19 AC 305 ms
26,496 KB
testcase_20 AC 157 ms
16,896 KB
testcase_21 AC 21 ms
5,376 KB
testcase_22 AC 172 ms
18,048 KB
testcase_23 AC 14 ms
5,376 KB
testcase_24 AC 245 ms
23,680 KB
testcase_25 AC 167 ms
17,408 KB
testcase_26 AC 54 ms
7,936 KB
testcase_27 AC 16 ms
5,376 KB
testcase_28 AC 356 ms
29,952 KB
testcase_29 AC 366 ms
30,080 KB
testcase_30 AC 351 ms
30,080 KB
testcase_31 AC 339 ms
29,952 KB
testcase_32 AC 345 ms
30,080 KB
testcase_33 AC 346 ms
29,952 KB
testcase_34 AC 338 ms
29,952 KB
testcase_35 AC 339 ms
30,080 KB
testcase_36 AC 345 ms
30,080 KB
testcase_37 AC 340 ms
30,080 KB
testcase_38 AC 340 ms
30,080 KB
testcase_39 AC 338 ms
30,080 KB
testcase_40 AC 353 ms
30,080 KB
testcase_41 AC 341 ms
29,952 KB
testcase_42 AC 343 ms
30,080 KB
testcase_43 AC 2 ms
5,376 KB
testcase_44 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local n = io.read("*n")
local a = {}
for i = 1, n do
  a[i] = {io.read("*n")}
end
for i = 1, n do
  a[i][2] = io.read("*n")
end
table.sort(a, function(x, y) return x[1] < y[1] end)
local ret = 0LL
local retpos = a[1][1]
local bias = 0LL
local ang = 0LL

for i = 1, n do
  ang = ang - a[i][2]
  bias = bias + a[i][2] * a[i][1]
end
do
  local x = a[1][1]
  ret = ang * x + bias
end
for i = 1, n - 1 do
  ang = ang + 2 * a[i][2]
  bias = bias - 2 * a[i][2] * a[i][1]
  local x = a[i + 1][1]
  local z = ang * x + bias
  if z < ret then
    ret = z
    retpos = x
  end
end
local str = tostring(ret):gsub("LL", "")
print(retpos .. " " .. str)
0