QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#652830#8242. V-Diagram111111qqqqqqTL 1ms5704kbC++231.4kb2024-10-18 19:11:292024-10-18 19:11:46

Judging History

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

  • [2024-10-18 19:11:46]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:5704kb
  • [2024-10-18 19:11:29]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define cmin(a,b) a=min(a,b)
#define cmax(a,b) a=max(a,b)
#define modd(a,b) a=a%b
#define pb push_back
#define db double
#define lowbit(x) x&(-x)
#define cerr(x) cout<<#x<<"="<<x<<endl
#define fi first
#define se second
const ll mod=1e9+7;
#define N 300010
const db eps=1e-10;
int n,pos;
db a[N],sum=0,pre[N];
ll ksm(ll a,ll b) {ll ans=1,bs=a;while(b) {if(b&1) ans=ans*bs%mod;bs=bs*bs%mod;b>>=1;}return ans;}
bool ck(db mid) {
    db s=sum-mid*n;
    if(s>=0) return 1;
    s=pre[pos+1]-mid*(pos+1);
    if(s>=0) return 1;
    s=pre[n]-pre[pos-2]-mid*(n-pos+2);
    return s>=0;
}//平均值最大>=mid,左边的可以拼上右边的
//只有3种情况,[1,n],[1,i+1],[i-1,n],如果最小值在i位置的话
void solve() {
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) pre[i]=pre[i-1]+a[i];
    sum=accumulate(a+1,a+n+1,0ll);
    pos=1;
    for(int i=2;i<n;i++) if(a[i]<a[i-1] && a[i]<a[i+1]) {pos=i;break;}
    db l=0,r=*max_element(a+1,a+n+1),mid;
    while(r-l>eps) {
        mid=(l+r)/2;
        if(ck(mid)) l=mid;
        else r=mid;
    }
    cout<<fixed<<setprecision(12)<<l<<endl;
}
int main() {
    ios::sync_with_stdio(0);cin.tie(0);cout.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: 5704kb

input:

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

output:

6.749999999956
5.833333333314

result:

ok 2 numbers

Test #2:

score: -100
Time Limit Exceeded

input:

100000
3
948511478 739365502 813471668
3
881046825 27458122 398507422
3
987554257 399092415 924260278
3
984128569 125199021 716360525
3
529589236 45783262 313507287
3
645443456 85994112 226010681
3
914820717 228360911 572267310
3
418958362 56703604 195276041
3
64461646 26764720 26995581
3
914535039 ...

output:


result: