QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#696874 | #8242. V-Diagram | Kopicy | TL | 1ms | 3940kb | C++23 | 1.5kb | 2024-11-01 04:41:29 | 2024-11-01 04:41:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for(int i=(a);i<=(b);++i)
#define sz(x) (int)x.size()
#define endl "\n"
const int N = 2e5, mod = 1e9 + 7, inf = 1e18;
void solve() {
int n;
cin>>n;
vector<int> a(n+5);
rep(i,1,n) cin>>a[i];
vector<int> pre(n+5);
rep(i,1,n) pre[i]=pre[i-1]+a[i];
vector<int> f(n+1),g(n+1);
#define db double
auto chk=[&](db x){
for(int i=1;i<=n;){
if(a[i+1]==a[i]){
i++;
continue;
}
int lo=i+1;
while(lo<=n && a[lo]<a[lo-1]) lo++;
int ro=lo;int lb=lo-1;
db mx=-inf;
while(ro<=n && a[ro]>a[ro-1]){
mx=max(1.0*pre[ro]-x*ro,mx);
ro++;
}
if(ro-i<3){
i=ro;
continue;
}
for(int j=i;j<lb;j++){
db ans2=pre[j-1]-(j-1)*x;
if(ans2<=mx) return true;
}
i=ro;
}
return false;
};
db lo=0,ro=1e9;
while((ro-lo)>1e-9){
db mid=(lo+ro)/2;
if(chk(mid)) lo=mid;
else ro=mid;
}
cout<<setprecision(10)<<lo<<endl;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int64_t tt = 1;
cin >> tt;
rep(kase, 1, tt) solve();
}
/*
2
4
8 2 7 10
6
9 6 5 3 4 8
*/
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3940kb
input:
2 4 8 2 7 10 6 9 6 5 3 4 8
output:
6.75 5.833333333
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 ...