QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#444016#8524. Weather Forecastucup-team3734#WA 0ms3984kbC++231.7kb2024-06-15 17:04:412024-06-15 17:04:43

Judging History

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

  • [2024-06-15 17:04:43]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3984kb
  • [2024-06-15 17:04:41]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long i64;
typedef unsigned long long u64;
typedef double lf;

int check(const vector<int> &a, lf x) {
    int n = (int) a.size();
    vector<lf> b(n + 1);
    b[0] = 0;
    for (int i = 0; i < n; i++) {
        b[i + 1] = b[i] + a[i] - x;
    }

    vector<lf> c;
    for (int i = 0; i <= n; i++) {
        if (b[i] > 0 && b[i] < b.back())
        c.push_back(b[i]);
    }
    
    if (c.empty()) {
        if (b[0] < b.back())
            return 1;
        return 0;
    }
    b = c;
    n = (int) b.size();

    static constexpr lf INF = 1e18;
    vector<lf> d(n + 1, INF);
    d[0] = -INF;

    for (int i = 0; i < n; i++) {
        int l = (int) (upper_bound(d.begin(), d.end(), a[i]) - d.begin());
        if (d[l - 1] < a[i] && a[i] < d[l]) {
            d[l] = a[i];
        }
    }

    int ans = 0;
    for (int l = 0; l <= n; l++) {
        if (d[l] < INF)
            ans = l;
    }
    return ans + 1;
}

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int &x : a) {
        cin >> x;
    }
    lf left = *min_element(a.begin(), a.end()), right = *max_element(a.begin(), a.end());
    while (right - left > 1e-5) {
        lf mid = (left + right) / 2;
        if (check(a, mid) >= k) {
            left = mid;
        } else {
            right = mid;
        }
    }
    cout << fixed << setprecision(10) << left << '\n';
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    int t = 1;
    // cin >> t;
    for (int i = 0; i < t; i++) {
        solve();
    }
}

詳細信息

Test #1:

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

input:

7 3
1 3 1 2 2 2 1

output:

1.6666641235

result:

ok found '1.66666', expected '1.66667', error '0.00000'

Test #2:

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

input:

1 1
1

output:

1.0000000000

result:

ok found '1.00000', expected '1.00000', error '0.00000'

Test #3:

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

input:

2 1
2 1

output:

1.4999923706

result:

ok found '1.49999', expected '1.50000', error '0.00001'

Test #4:

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

input:

3 2
2 4 4

output:

2.9999923706

result:

ok found '2.99999', expected '3.00000', error '0.00001'

Test #5:

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

input:

4 2
6 7 3 12

output:

6.4999952316

result:

ok found '6.50000', expected '6.50000', error '0.00000'

Test #6:

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

input:

5 3
17 23 13 12 21

output:

16.4999957085

result:

ok found '16.50000', expected '16.50000', error '0.00000'

Test #7:

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

input:

7 4
3 37 46 23 46 6 31

output:

26.4999958277

result:

wrong answer 1st numbers differ - expected: '23.00000', found: '26.50000', error = '3.50000'