QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#650099#8242. V-Diagram111111qqqqqqTL 1ms5972kbC++231.3kb2024-10-18 12:52:422024-10-18 12:52:43

Judging History

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

  • [2024-10-18 12:52:43]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:5972kb
  • [2024-10-18 12:52:42]
  • 提交

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],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) {
    for(int i=1;i<=n;i++) pre[i]=pre[i-1]+a[i]-mid;
    db mx=0,mxx=0;
    for(int i=1;i<pos;i++) cmax(mx,pre[pos-1]-pre[i-1]);
    for(int i=pos+1;i<=n;i++) cmax(mxx,pre[i]-pre[pos]);
    return mx+mxx+a[pos]-mid>=0;
}
void solve() {
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    pos=1;
    for(int i=2;i<n;i++) if(a[i]<a[i-1] && a[i]<a[i+1]) pos=i;
    db l=0,r=*max_element(a+1,a+n+1),mid;
    // cout<<log2(1e18)<<endl;
    int cnt=0;
    while(fabs(r-l)>eps) {
        // if(++cnt==100) break;
        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: 5972kb

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: