QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#442180#8524. Weather Forecastucup-team3699#WA 1ms6112kbC++231.3kb2024-06-15 09:50:032024-06-15 09:50:06

Judging History

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

  • [2024-06-15 09:50:06]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6112kb
  • [2024-06-15 09:50:03]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

#define int long long 
#define pb push_back
#define F first 
#define S second

const int mol=1e9+7;

int a[200005];
int bit[200005];
    int n, k;

void upd(int now, int val){
    while(now<=n){
        bit[now]=max(bit[now], val), now+=now&-now;
    }
}

int va1l(int now){
    int ans=-1;
    while(now) ans=max(ans, bit[now]), now-=now&-now;
    return ans;
}

int pre[200005];
const double eps=1e-9;
bool ok(double val){
    vector<double>ch;
    for(int i=1;i<=n;i++) ch.pb(-val*i+pre[i]);
    sort(ch.begin(), ch.end());
    int ans;
    for(int i=1;i<=n;i++) bit[i]=-1;
    for(int i=1;i<=n;i++){
        int q=0;
        if(pre[i]>=val*i||abs(pre[i]-val*i)<=eps) q=1;
        int id=lower_bound(ch.begin(), ch.end(), -val*i+pre[i])-ch.begin()+1;
        q=max(q, va1l(id)+1);
        upd(id, q);
        if(i==n) ans=q;
    }
    return ans>=k;
}
void solve(){
    cin>>n>>k;
    
    for(int i=1;i<=n;i++) cin>>a[i], pre[i]=pre[i-1]+a[i];

    double l=1, r=1000;

    for(int i=1;i<=50;i++){
        double mid=(l+r)/2;
        if(ok(mid)) l=mid;
        else r=mid;
    }
    cout<<fixed<<setprecision(10)<<l<<"\n";
}

signed main(){
    ios::sync_with_stdio(0);cin.tie(0);
    // int t;
    // cin>>t;
    // while(t--)
    solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

7 3
1 3 1 2 2 2 1

output:

1.6666666667

result:

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

Test #2:

score: 0
Accepted
time: 1ms
memory: 5924kb

input:

1 1
1

output:

1.0000000010

result:

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

Test #3:

score: 0
Accepted
time: 1ms
memory: 5864kb

input:

2 1
2 1

output:

1.5000000005

result:

ok found '1.50000', expected '1.50000', error '0.00000'

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 5884kb

input:

3 2
2 4 4

output:

4.0000000000

result:

wrong answer 1st numbers differ - expected: '3.00000', found: '4.00000', error = '1.00000'