QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#661831 | #8037. Gambler's Ruin | inoader | WA | 1ms | 6108kb | C++14 | 1.1kb | 2024-10-20 18:25:14 | 2024-10-20 18:25:14 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int __int128
#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 long double eps=1e-13;
long double p[N];
int n;
struct node{
long double p;
int c;
}a[N];
bool cmp(node x,node y){
return x.p>y.p;
}
void sol(){
n=read();
for(int i=1;i<=n;++i){
cin>>a[i].p;
a[i].c=read();
}
sort(a+1,a+1+n,cmp);
int sx=0;
long double ans=0;
int r=n;
int sy=0;
long double y=1;
for(int i=1;i<=n;++i){
while(i>r){
sy-=a[r+1].c;
y=1/(1-a[r+1].p);
++r;
}
sx+=a[i].c;
if(a[i].p==a[i+1].p)continue;
long double x=1/a[i].p;
while(r>i){
int rr=r;
int ssy=sy+a[r].c;
while(rr-1==rr)ssy+=a[--rr].c;
long double yy=1/(1-a[rr].p);
if(ssy-max(sx*x,ssy*yy)>sy-max(sx*x,sy*y))sy=ssy,y=yy,r=rr-1;
else break;
}
ans=max(ans,sx+sy-max(sx*x,sy*y));
}
printf("%.10Lf\n",ans);
}
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: 5892kb
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: 5876kb
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: 5888kb
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: 6108kb
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: 1ms
memory: 6056kb
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: 6076kb
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: -100
Wrong Answer
time: 1ms
memory: 5884kb
input:
3 0.2 100 0.2 100 0.8 100
output:
75.0000000000
result:
wrong answer 1st numbers differ - expected: '50.0000000', found: '75.0000000', error = '0.5000000'