QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#756389 | #8037. Gambler's Ruin | jingjingya | WA | 1ms | 5944kb | C++23 | 1.1kb | 2024-11-16 20:17:30 | 2024-11-16 20:17:31 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned int;
const int N = 1e6+10;
struct tp{
double p,c;
}a[N];
bool cmp(tp a,tp b){
return a.p>b.p;
}
double pre[N],suf[N];
signed main() {
int n;cin>>n;
for(int i = 1;i<=n;i++){
cin>>a[i].p>>a[i].c;
}
sort(a+1,a+1+n,cmp);
for(int i = 1;i<=n;i++){
pre[i] = pre[i-1] + a[i].c;
}
for(int i = n;i>0;i--){
suf[i] = suf[i+1] + a[i].c;
}
double ans = 0;
double x,y;
int j = n;
for(int i = 1;i<=n;i++){
if(j<=i)break;
x = 1/a[i].p;
y = 1/(1-a[j].p);
double a1 = x * pre[i];
double a2 = y * suf[j];
while(a2<a1){
j--;
y = 1/(1-a[j].p);
a2 = y * suf[j];
}
if(j<=i){
j = i+1;
y = 1/(1-a[j].p);
ans = max(ans,pre[i] + suf[j] - max(x*pre[i],y*suf[j]));
break;
}
ans = max(ans,pre[i] + suf[j] - max(x*pre[i],y*suf[j]));
y = 1/(1-a[j+1].p);
ans = max(ans,pre[i] + suf[j+1] - max(x*pre[i],y*suf[j+1]));
}
cout<<fixed<<setprecision(10)<<ans<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5904kb
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: 5896kb
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: 5944kb
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: 5876kb
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: 5936kb
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: 0ms
memory: 5900kb
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'