結果

問題 No.2438 Double Least Square
ユーザー ebi_flyebi_fly
提出日時 2023-08-12 00:40:10
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,243 bytes
コンパイル時間 1,882 ms
コンパイル使用メモリ 199,440 KB
最終ジャッジ日時 2025-02-16 02:32:37
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 RE * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,s,n) for(int i = int(s); i < int(n); i++)

using i64 = std::int64_t;

template<class T>
bool chmin(T &a, T b) {
    if(a < b) return false;
    a = b;
    return true;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    int n;
    i64 h;
    std::cin >> n >> h;
    std::vector<std::pair<i64,i64>> ps(n);
    for(auto &[x, y]: ps) {
        std::cin >> x >> y;
    }
    assert(n <= 25);
    using ld = long double;
    ld ans = std::numeric_limits<ld>::max();
    auto calc_score = [](const std::vector<i64> a) -> ld {
        if(a[2] == 0) {
            assert(a[1] == 0 && a[0] == 0);
            return 0;
        }
        return ld(a[0]) - ld(a[1] * a[1]) / ld(4 * a[2]);

    };
    rep(bit,0,1<<n) {
        std::vector<i64> u(3, 0), d(3, 0);
        rep(i,0,n) {
            auto [x, y] = ps[i];
            if((bit >> i) & 1) {
                u[0] += (y - h) * (y - h);
                u[1] += -2*x*(y-h);
                u[2] += x*x;
            }
            else {
                d[0] += y*y;
                d[1] += -2*x*y;
                d[2] += x*x;
            }
        }
        chmin(ans, calc_score(u) + calc_score(d));
    }
    std::cout << ans << '\n';
}
0