QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#627479#5667. Meeting PlacesKowerKoint#TL 0ms0kbC++202.3kb2024-10-10 16:05:092024-10-10 16:05:11

Judging History

你现在查看的是最新测评结果

  • [2024-10-10 16:05:11]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-10-10 16:05:09]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
    int n, k; cin >> n >> k;
    vector<ll> X(n), Y(n);
    cin >> X[0];
    auto gen = [&](ll x) {
        return (x * (233811181) + 1) % ((1LL << 31) - 1);
    };
    Y[0] = gen(X[0]);
    for(int i = 1; i < n; i++) {
        X[i] = gen(Y[i-1]);
        Y[i] = gen(X[i]);
    }
    auto cos = [&](int l, int r) {
        auto calc = [&](double x, double y) {
            double mx = 0.;
            for(int i = l; i < r; i++) {
                double dx = X[i]-x;
                double dy = Y[i]-y;
                double d = dx*dx+dy*dy;
                if(mx < d) mx = d;
            }
            return mx;
        };
        double lx = 0, rx = (double)((1LL << 31) - 1);
        constexpr int CNT = 50;
        int xt = CNT;
        auto sim_y = [&](double x) {
            double ly = 0, ry = (double)((1LL << 31) - 1);
            int yt = CNT;
            while(yt--) {
                double y1 = (ly*2+ry) / 3;
                double y2 = (ly+ry*2) / 3;
                if(calc(x, y1) < calc(x, y2)) ry = y2;
                else ly = y1;
            }
            return calc(x, ly);
        };
        while(xt--) {
            double x1 = (lx*2+rx) / 3;
            double x2 = (lx+rx*2) / 3;
            if(sim_y(x1) < sim_y(x2)) rx = x2;
            else lx = x1;
        }
        return sim_y(lx);
    };
    constexpr double INF = 4e18;
    cout << fixed << setprecision(10);
    vector cost(n+1, vector(n+1, INF));
    for(int l = 0; l < n; l++) {
        for(int r = l+1; r <= n; r++) {
            cost[l][r] = sqrt(cos(l, r));
        }
    }
    if(n <= 50) {
        vector dp(k+1, vector(n+1, INF));
        dp[0][0] = 0;
        for(int i = 0; i < k; i++) {
            for(int l = 0; l < n;l++) {
                for(int r = l+1; r <= n; r++) {
                    double c = cost[l][r];
                    if(dp[i+1][r] > dp[i][l]+c) dp[i+1][r] = dp[i][l]+c;
                }
            }
        }
        cout << dp[k][n] << '\n';
        return 0;
    }
    double ans = INF;
    for(int l = 0; l+n-(k-1) <= n; l++) {
        int r = l+n-(k-1);
        double c = sqrt(cos(l, r));
        cerr << l << ' ' << c << endl;
        if(ans > c) ans = c;
    }
    cout << ans << '\n';
}

详细

Test #1:

score: 0
Time Limit Exceeded

input:

100 23 213

output:


result: