QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#712705#9540. Double 11scorpiochWA 1ms3904kbC++201.5kb2024-11-05 16:43:422024-11-05 16:43:42

Judging History

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

  • [2024-11-05 16:43:42]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3904kb
  • [2024-11-05 16:43:42]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long double db;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, k;
    cin >> n >> k;

    vector<db> a(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        a[i] += a[i - 1];
    }
    auto solve = [&](db C) {
        vector<pair<db, int>> dp(n + 1, {1e20L, 0});
        vector<int> x(n + 1, 0);
        auto check = [&](int j, int i) {
            if (j >= i) return;
            db cost = db(sqrtl((i - j) * (a[i] - a[j]))) + C; // totally monotone
            // cerr << j << " " << i << " " << sqrtl((i - j) * (a[i] - a[j])) << " " << cost << " " << C << endl;
            if (dp[j].first + cost < dp[i].first) {
                dp[i] = {dp[j].first + cost, dp[j].second + 1};
                x[i] = j;
            }
        };
        auto dfs = [&](auto &&self, int l, int r) -> void {
            if (l + 1 >= r) return;
            int m = (l + r) / 2;
            for (int i = x[l]; i <= x[r]; i++) check(i, m);
            self(self, l, m);
            for (int i = l + 1; i <= m; i++) check(i, r);
            self(self, m, r);
        };
        dp[0] = {0.0, 0};
        check(0, n);
        dfs(dfs, 0, n);
        return dp[n];
    };

    db L = 0, R = 1e12;
    for (int i = 100; i; i--) {
        db m = (L + R) / 2.0;
        auto [x, y] = solve(m);
        y >= k ? L = m : R = m;
    }
    auto [x, y] = solve(L);
    cout << fixed << setprecision(13) << x - k * L << endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3888kb

input:

4 2
1 2 3 4

output:

6.1911471295571

result:

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

Test #2:

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

input:

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

output:

22.5916253665141

result:

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

Test #3:

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

input:

1 1
1

output:

1.0000000000000

result:

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

Test #4:

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

input:

1 1
100000

output:

316.2277660369873

result:

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

Test #5:

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

input:

7 1
10 47 53 9 83 33 15

output:

41.8330013155937

result:

ok found '41.833001316', expected '41.833001327', error '0.000000000'

Test #6:

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

input:

8 5
138 1702 119 1931 418 1170 840 1794

output:

243.2426507096569

result:

wrong answer 1st numbers differ - expected: '233.9016546', found: '243.2426507', error = '0.0399356'