QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#537308 | #8037. Gambler's Ruin | rotcar07 | WA | 0ms | 4048kb | C++14 | 1.0kb | 2024-08-30 09:45:29 | 2024-08-30 09:45:31 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n;
double sum[1000005];
constexpr double eps=1e-8;
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n;vector<pair<double,int>>v(n);
for(auto&x:v) cin>>x.first>>x.second;
sort(v.begin(),v.end());
for(int i=1;i<=n;i++) sum[i]=sum[i-1]+v[i-1].second;
auto calc=[&](int x) -> double {
if(v[x-1].first>eps) return 1/v[x-1].first*(sum[n]-sum[x-1]);
else return 1e18;
};
auto calcw=[&](int x) -> double {
if(1-v[x-1].first>eps) return 1/(1-v[x-1].first)*sum[x];
else return 1e18;
};
double ans=sum[n]-calc(1),mx=-1e18;
int pos=0;
for(int i=2;i<=n;i++)if(v[i-1].first-eps>v[i-2].first){
pos++;
double k=calc(i);
while(calcw(pos)-eps>=k) pos--;
ans=max(ans,sum[n]-sum[i-1]+max(sum[pos]-k,mx));
// cout<<ans<<' '<<pos<<' '<<mx<<' '<<k<<'\n';
mx=max(sum[i]-calcw(i),mx);
}
cout<<fixed<<setprecision(10)<<max(ans,0.0)<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4048kb
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: 0ms
memory: 3980kb
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: 0ms
memory: 4048kb
input:
1 0 1
output:
0.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3760kb
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: 3760kb
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: 0ms
memory: 3912kb
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: 0ms
memory: 3760kb
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'