QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#613492#8524. Weather ForecastTecy#WA 0ms3848kbC++201.4kb2024-10-05 14:05:352024-10-05 14:09:14

Judging History

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

  • [2024-10-05 14:09:14]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3848kb
  • [2024-10-05 14:05:35]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const double eps = 1e-6;
void solve() {
    int n,k;
    cin >> n >> k;
    vector<int>a(n + 1);
    for(int i = 1;i <= n;i++) cin >> a[i];
    auto check = [&](double x){
        vector<double>b(n + 1),suf(n + 2);
        for(int i = 1;i <= n;i++){
            b[i] = (double)(a[i] - x);
            // cerr << b[i] << ' ';
        }
        // cerr << endl;
        suf[n + 1] = 0;
        for(int i = n;i;i--){
            suf[i] = suf[i + 1] + b[i];
        }
        int res = 1;
        double sum = 0;
        for(int i = 1;i < n;i++){
            sum += b[i];
            // cerr << sum << ' ' << suf[i + 1] << endl;
            if(b[i + 1] <= eps && sum + b[i + 1] >= -eps) continue; 
            if(sum >= eps && suf[i + 1] >= eps){
                res++;
                sum = 0;
            }
        }
        return res >= k;
    };    
    double l = 0,r = 1e3;
    while(r - l > eps){
        double mid = (l + r) / 2;
        // cerr << mid << ' ' << l << ' ' << r << endl;
        if(check(mid)) l = mid;
        else r = mid;
    }
    cout << fixed << setprecision(12) << l << '\n';
}
signed main() {
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);

    int T = 1;
    // cin >> T;
    for (int i = 1; i <= T; i++) {
        solve();
    }

    return 0;
}
/*
7 3
1 3 1 2 2 2 1
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

7 3
1 3 1 2 2 2 1

output:

1.666666008532

result:

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

Test #2:

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

input:

1 1
1

output:

999.999999068677

result:

wrong answer 1st numbers differ - expected: '1.00000', found: '1000.00000', error = '999.00000'