結果

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

ソースコード

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;
    i64 ret = 0;
    rep(i,0,n) {
        i64 x,y;
        std::cin >> x >> y;
        ps.emplace_back(x, y);
        if(x == 0) {
            ret += std::min(h - y, y) * std::min(h - y, y);
        }
    }
    n = ps.size();
    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));
    }
    ans += ld(ret);
    std::cout << ans << '\n';
}
0