QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#120054 | #4355. Seesaw | lmeowdn# | 0 | 3ms | 6120kb | C++14 | 2.4kb | 2023-07-06 12:44:46 | 2024-07-04 00:21:03 |
Judging History
answer
#include<bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
template<typename T,typename U>
T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U>
T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x) {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x) {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x) {return (x==0?-1:__builtin_ctzll(x));}
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef tuple<int,int,int> tiii;
int read() {
int x=0,w=1; char c=getchar();
while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
return x*w;
}
const int N=2e5+5;
const ld inf=1e9,eps=1e-9;
int n,a[N],s[N],f[105][105];
ld ans=inf,b[N];
ld avg(int l,int r) {
return 1.*(s[r]-s[l-1])/(r-l+1);
}
bool work(ld L,ld R,int l,int r) {
if(l==r) return 1;
if(f[l][r]!=-1) return f[l][r];
ld pl=avg(l,r-1), pr=avg(l+1,r);
bool res=0;
if(L<=pl&&pl<=R) res|=work(L,R,l,r-1);
if(L<=pr&&pr<=R) res|=work(L,R,l+1,r);
return f[l][r]=res;
}
signed main() {
n=read();
rep(i,1,n) a[i]=read(), s[i]=s[i-1]+a[i];
rep(i,1,n) b[i]=a[i]; b[n+1]=avg(1,n);
rep(i,1,n+1) if(b[i]-eps<avg(1,n)) {
ld L=b[i];
ld x=0, y=inf, res=inf;
x=max(x,avg(1,n)-L);
while(y-x>eps) {
ld p=(x+y)/2;
rep(l,1,n) rep(r,l+1,n) f[l][r]=-1;
if(work(L,L+p,1,n)) res=p, y=p;
else x=p;
}
chmin(ans,res);
}
rep(i,1,n+1) if(b[i]+eps>avg(1,n)) {
ld L=b[i];
ld x=0, y=inf, res=inf;
x=max(x,L-avg(1,n));
while(y-x>eps) {
ld p=(x+y)/2;
rep(l,1,n) rep(r,l+1,n) f[l][r]=-1;
if(work(L-p,L,1,n)) res=p, y=p;
else x=p;
}
chmin(ans,res);
}
printf("%.8Lf\n",ans);
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 1
Accepted
time: 1ms
memory: 5944kb
input:
2 925278587 966813970
output:
20767691.50000000
result:
ok found '20767691.500000000', expected '20767691.500000000', error '0.000000000'
Test #2:
score: -1
Wrong Answer
time: 3ms
memory: 6120kb
input:
20 7902238 121690240 160345001 255257832 269315023 288280211 296247186 353929891 494812700 530994847 567379029 567478415 612943598 644028258 654380821 696407711 708542915 738196686 743020754 760907139
output:
57459167.25000000
result:
wrong answer 1st numbers differ - expected: '52991294.1666667', found: '57459167.2500000', error = '0.0843133'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%