QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#661647 | #8037. Gambler's Ruin | MENDAX | WA | 1ms | 6088kb | C++20 | 1.0kb | 2024-10-20 17:17:03 | 2024-10-20 17:17:04 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
inline int read(){
int x=0,k=1;char c=getchar();
while(c<'0'||c>'9'){
if(c=='-')k=-1;
c=getchar();
}
while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
return x*k;
}
const int N=1e6+5;
const double eps=1e-13;
double p[N];
int c[N];
int n;
double cal(double x){
int sx=0;
for(int i=1;i<=n;++i)if(p[i]*x>=1){
sx+=c[i];
}
double l=1,r=2;
int sy=0;
double m=sx*x;
while(l+eps<r){
int cy=0;
double y=(l+r)/2;
for(int i=1;i<=n;++i){
if(p[i]*x>=1)continue;
if((1-p[i])*y>=1)cy+=c[i];
}
if(cy*y-eps<m)l=y,sy=max(sy,cy);
else r=y-eps;
}
return sx+sy-sx*x;
}
void sol(){
n=read();
for(int i=1;i<=n;++i)cin>>p[i]>>c[i];
double l=1,r=1e6;
while(l+eps<r){
double lm=l+(r-l)/3,rm=r-(r-l)/3;
// cout<<lm<<' '<<rm<<endl;
// cout<<cal(lm)<<"?"<<cal(rm)<<endl;
if(cal(lm)<cal(rm))l=lm;
else r=rm;
}
printf("%.10f\n",cal((l+r)/2));
}
signed main(){
int T=1;
while(T--)sol();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5960kb
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: 6020kb
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: 5856kb
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: 5916kb
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: 5828kb
input:
1 0.5 100
output:
0.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #6:
score: 0
Accepted
time: 1ms
memory: 5900kb
input:
3 0.4 100 0.6 100 0.6 100
output:
0.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #7:
score: 0
Accepted
time: 1ms
memory: 6032kb
input:
3 0.2 100 0.2 100 0.8 100
output:
50.0000000000
result:
ok found '50.0000000', expected '50.0000000', error '0.0000000'
Test #8:
score: -100
Wrong Answer
time: 1ms
memory: 6088kb
input:
2 0.999999 1000000 0.999998 2
output:
0.0000000000
result:
wrong answer 1st numbers differ - expected: '0.9999990', found: '0.0000000', error = '0.9999990'