QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#704314#9540. Double 11ucup-team5062#WA 0ms3984kbC++201.6kb2024-11-02 19:44:282024-11-02 19:44:30

Judging History

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

  • [2024-11-02 19:44:30]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3984kb
  • [2024-11-02 19:44:28]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, M;
    cin >> N >> M;
    vector<ll> S(N);
    for (auto& x : S) cin >> x;
    ranges::sort(S);
    S.insert(begin(S), 0ll);
    for (int i = 0; i < N; ++i) S[i + 1] += S[i];

    const auto solve = [&](double lambda) -> double {
        vector<double> dp(N + 1, 1e18);
        dp[0] = 0;
        const auto cost = [&](int i, int j) {
            return sqrt((S[j] - S[i]) * (j - i)) + dp[i] + lambda;
        };

        vector<int> amin(N + 1);
        const auto check = [&](int l, int r) {
            const double tmp = cost(l, r);
            if (dp[r] > tmp) {
                dp[r] = tmp;
                amin[r] = l;
            }
        };
        auto dfs = [&](auto&& self, int l, int r) -> void {
            if (r - l == 1) return;
            const int m = (l + r) / 2;
            for (int k = amin[l]; k <= amin[r]; k++) check(k, m);
            self(self, l, m);
            for (int k = l + 1; k <= m; k++) check(k, r);
            self(self, m, r);
        };
        check(0, N);
        dfs(dfs, 0, N);

        return dp[N] - lambda * M;
    };

    double lmin = -1e9, lmax = +1e9;
    for (int k = 0; k < 70; ++k) {
        double m1 = (lmin * 2 + lmax * 1) / 3;
        double m2 = (lmin * 1 + lmax * 2) / 3;
        if (solve(m1) < solve(m2)) {
            lmin = m1;
        } else {
            lmax = m2;
        }
    }

    cout << fixed << setprecision(20);
    cout << solve((lmin + lmax) / 2) << '\n';

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3984kb

input:

4 2
1 2 3 4

output:

6.19114712955711965492

result:

ok found '6.191147130', expected '6.191147130', error '0.000000000'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3928kb

input:

10 3
1 2 3 4 5 6 7 8 9 10

output:

22.59162536651412622746

result:

ok found '22.591625367', expected '22.591625367', error '0.000000000'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3868kb

input:

1 1
1

output:

1.00000000000000000000

result:

ok found '1.000000000', expected '1.000000000', error '0.000000000'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3984kb

input:

1 1
100000

output:

316.22776603698730468750

result:

ok found '316.227766037', expected '316.227766017', error '0.000000000'

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3916kb

input:

7 1
10 47 53 9 83 33 15

output:

41.83300137519836425781

result:

wrong answer 1st numbers differ - expected: '41.8330013', found: '41.8330014', error = '0.0000000'