QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#537345 | #8037. Gambler's Ruin | rotcar07 | RE | 0ms | 4064kb | C++14 | 1.4kb | 2024-08-30 10:19:26 | 2024-08-30 10:19:26 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n;
#define double long double
double sum[1000005];
constexpr double eps=1e-9;
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]-min(calc(1),calcw(n));
int pos=n;
for(int i=2;i<=n;i++)
if(v[i-1].first-eps>v[i-2].first){
double k=calc(i);
while(pos>0&&(calcw(pos)-eps>=k||v[pos].first-eps<=v[pos-1].first)) pos--;
if(pos<1) break;
if(pos>=i) ans=max(ans,sum[n]-k);
ans=max(ans,sum[n]-sum[i-1]+sum[pos]-k);
}pos=1;
for(int i=n-1;i>=1;i--)
if(v[i].first-eps>v[i-1].first){
double k=calcw(i);
while(pos<=n&&(calc(pos)-eps>=k||v[pos-1].first-eps<=v[pos-2].first)) pos++;
if(pos>n) break;
if(pos<=i) ans=max(ans,sum[n]-k);
ans=max(ans,sum[i]+sum[n]-sum[pos-1]-k);
// cout<<ans<<' '<<pos<<' '<<k<<'\n';
}
cout<<fixed<<setprecision(10)<<max<double>(ans,0.0)<<'\n';
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3776kb
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: 3968kb
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: 3772kb
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: 4064kb
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: 3832kb
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: 3972kb
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: 0ms
memory: 3848kb
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: 0
Accepted
time: 0ms
memory: 3760kb
input:
2 0.999999 1000000 0.999998 2
output:
0.9999990000
result:
ok found '0.9999990', expected '0.9999990', error '0.0000000'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3860kb
input:
2 0 100000 0.000001 1
output:
0.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3888kb
input:
2 0 1000000000 0.000001 1
output:
1.0000000000
result:
ok found '1.0000000', expected '1.0000000', error '0.0000000'
Test #11:
score: -100
Runtime Error
input:
1000000 0.375733 595197307 0.505261 377150668 0.517039 15795246 0.448099 228176467 0.529380 871983979 0.905546 876268308 0.095891 272104456 0.500302 916153337 0.128705 355768079 0.070600 78747362 0.444107 466118868 0.194987 298494965 0.462293 593292779 0.287909 838058266 0.237226 934603199 0.391909 ...