QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#771508 | #8037. Gambler's Ruin | caiwen | WA | 2ms | 12156kb | C++14 | 1.8kb | 2024-11-22 13:39:44 | 2024-11-22 13:39:44 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define ls(k) (k)<<1
#define rs(k) (k)<<1|1
#define debug(x) cout<<#x<<"="<<x<<endl
using namespace std;
const int inf=0x3f3f3f3f3f3f3f3f;
const int mod=0;
typedef pair<int,int> pii;
typedef pair<double,int> pdi;
#define _ 1000006
pdi e[_];
int n;
double x[_],y[_],dx[_],dy[_];
int px,py,sx[_],sy[_],tx,ty;
const double eps=1e-8;
inline void subtask(){
cin>>n;
for(int i=1;i<=n;i++) cin>>e[i].first>>e[i].second;
sort(e+1,e+n+1,[](pdi x,pdi y){return x.first>y.first;});
for(int i=1;i<=n;i++){
if(fabs(e[i].first)<eps) break;
else px++,x[i]=1.0/e[i].first;
}
py=n+1;
for(int i=n;i>=1;i--){
double p=1-e[i].first;
if(fabs(p)<eps) break;
else py=i,y[i]=1.0/p;
}
tx=1,ty=n;
for(int i=1;i<=px;i++){
sx[i]=sx[i-1]+e[i].second,dx[i]=sx[i]-sx[i]*x[i];
if(dx[i]>dx[tx]) tx=i;
}
for(int i=n;i>=py;i--){
sy[i]=sy[i+1]+e[i].second,dy[i]=sy[i]-sy[i]*y[i];
if(dy[i]>dy[ty]) ty=i;
}
bool flag=0;
double aans;
for(int i=0;i<=px;i++){
int l=max(i+1,py),r=n,ans=n+1;
while(l<=r){
int mid=(l+r)>>1;
if(sy[mid]*y[mid]<sx[i]*x[i]){
ans=mid;
r=mid-1;
}else l=mid+1;
}
double loc=sx[i]-sx[i]*x[i];
if(ty>i) loc=max(loc,sx[i]+sy[ty]-max(sx[i]*x[i],sy[ty]*y[ty]));
loc=max(loc,sx[i]+sy[ans]-max(sx[i]*x[i],sy[ans]*y[ans]));
//debug(ans);
if(!flag){
flag=1;
aans=loc;
}else aans=max(aans,loc);
}
printf("%.10lf",aans);
}
signed main(){
//ios::sync_with_stdio(false);
int t=1;//cin>>t;
while(t--) subtask();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 12140kb
input:
2 1 15 0 10
output:
10.0000000000
result:
ok found '10.0000000', expected '10.0000000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 1ms
memory: 12084kb
input:
3 0.4 100 0.5 100 0.6 100
output:
33.3333333333
result:
ok found '33.3333333', expected '33.3333333', error '0.0000000'
Test #3:
score: 0
Accepted
time: 1ms
memory: 8056kb
input:
1 0 1
output:
0.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #4:
score: 0
Accepted
time: 1ms
memory: 10152kb
input:
2 1 0 1 100
output:
0.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #5:
score: 0
Accepted
time: 0ms
memory: 12156kb
input:
1 0.5 100
output:
0.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 12148kb
input:
3 0.4 100 0.6 100 0.6 100
output:
33.3333333333
result:
wrong answer 1st numbers differ - expected: '0.0000000', found: '33.3333333', error = '33.3333333'