結果
問題 | No.2438 Double Least Square |
ユーザー | abap34 |
提出日時 | 2023-08-16 02:32:00 |
言語 | Julia (1.10.2) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,394 bytes |
コンパイル時間 | 50 ms |
コンパイル使用メモリ | 6,692 KB |
実行使用メモリ | 343,252 KB |
最終ジャッジ日時 | 2024-10-01 17:36:42 |
合計ジャッジ時間 | 69,103 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,877 ms
308,568 KB |
testcase_01 | AC | 1,908 ms
308,544 KB |
testcase_02 | AC | 1,859 ms
307,564 KB |
testcase_03 | AC | 1,857 ms
308,216 KB |
testcase_04 | AC | 1,879 ms
308,428 KB |
testcase_05 | AC | 1,856 ms
307,280 KB |
testcase_06 | AC | 1,897 ms
308,396 KB |
testcase_07 | AC | 1,848 ms
308,372 KB |
testcase_08 | AC | 1,848 ms
307,800 KB |
testcase_09 | AC | 1,849 ms
308,500 KB |
testcase_10 | TLE | - |
testcase_11 | TLE | - |
testcase_12 | TLE | - |
testcase_13 | TLE | - |
testcase_14 | TLE | - |
testcase_15 | TLE | - |
testcase_16 | TLE | - |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | TLE | - |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | TLE | - |
testcase_23 | TLE | - |
testcase_24 | TLE | - |
testcase_25 | TLE | - |
testcase_26 | TLE | - |
testcase_27 | TLE | - |
testcase_28 | TLE | - |
testcase_29 | TLE | - |
testcase_30 | AC | 1,798 ms
308,420 KB |
testcase_31 | AC | 1,789 ms
307,624 KB |
testcase_32 | AC | 1,785 ms
308,412 KB |
ソースコード
using Printf function score(xy, x², y²) if x² == 0 return 0 end coef = xy / x² return y² + (coef^2 * x²) - (2coef * xy) end function main() N = parse(Int, readline()) H = parse(Int, readline()) x = zeros(Int, N) y = zeros(Int, N) for i in 1:N x[i], y[i] = parse.(Int, split(readline())) end slopes = (y .- (H // 2)) .// x slopes_perm = sortperm(slopes, rev=true) x_perm = sortperm(x, rev=true) xy = sum(x .* y) x² = sum(x .* x) y² = sum(y .* y) L_best = score(xy, x², y²) for i in eachindex(x) upper = slopes_perm[begin:i] lower = slopes_perm[i+1:end] upper_set = Set(upper) upper_x = getindex.(Ref(x), upper) upper_y = getindex.(Ref(y .- H), upper) upper_xy = sum(upper_x .* upper_y) upper_x² = sum(upper_x .* upper_x) upper_y² = sum(upper_y .* upper_y) lower_x = getindex.(Ref(x), lower) lower_y = getindex.(Ref(y), lower) lower_xy = sum(lower_x .* lower_y) lower_x² = sum(lower_x .* lower_x) lower_y² = sum(lower_y .* lower_y) L_u = score(upper_xy, upper_x², upper_y²) L_b = score(lower_xy, lower_x², lower_y²) L = L_u + L_b if L < L_best L_best = L end for j in eachindex(x) new_idx = x_perm[j] if new_idx in upper_set upper_xy -= x[new_idx] * (y[new_idx] - H) upper_x² -= x[new_idx]^2 upper_y² -= (y[new_idx] - H)^2 lower_xy += x[new_idx] * y[new_idx] lower_x² += x[new_idx]^2 lower_y² += y[new_idx]^2 else upper_xy += x[new_idx] * (y[new_idx] - H) upper_x² += x[new_idx]^2 upper_y² += (y[new_idx] - H)^2 lower_xy -= x[new_idx] * y[new_idx] lower_x² -= x[new_idx]^2 lower_y² -= y[new_idx]^2 end L_u = score(upper_xy, upper_x², upper_y²) L_b = score(lower_xy, lower_x², lower_y²) L = L_u + L_b if L < L_best L_best = L end end end @printf "%0.20f\n" L_best end main()