QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#622728 | #8037. Gambler's Ruin | sazhi | WA | 0ms | 4040kb | C++20 | 1.9kb | 2024-10-09 01:07:10 | 2024-10-09 01:07:11 |
Judging History
answer
// author: jieda
// file: cpp
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
# define fi first
# define se second
# define all(x) x.begin(),x.end()
# define stst stringstream
# define pb push_back
# define pf push_front
# define pp push
# define lowbit(x) (x)&(-x)
# define fa(i,op,n) for (int i = op; i <= n; i++)
# define fb(j,op,n) for (ll j = op; j >= n; j--)
# define fg(i,op,n) for (ll i = op; i != n; i = ne[i])
int dx[4] = {-1,0,1,0},dy[4] = {0,1,0,-1};
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
const int N = 1e5+10,INF = 0x3f3f3f3f,mod = 998244353;
const ll MOD = 212370440130137957ll;//hash(hight)
const int base = 131;
const double eps = 1e-3;
const int seed=10086,mo=1e6+7; //hash(lower)
int prime = 233317;
void solve(){
int n;cin>>n;
vector<pair<double,int>> a(n+1);
fa(i,1,n){
cin>>a[i].fi>>a[i].se;
}
sort(a.begin()+1,a.end(),[&](auto p1,auto p2){
return p1.fi>p2.fi;
});
int cnt = 0;
for(int i = 1;i<=n;i++){
if(i == 1||fabs(a[i].fi-a[i-1].fi)>eps) a[++cnt] = a[i];
else a[cnt].se += a[i].se;
}
n = cnt;
// cout<<n<<'\n';
vector<double> pre(n+2),suf(n+2);
for(int i = 1;i<=n;i++){
pre[i] = pre[i-1]+a[i].se;
}
for(int i = n;i>=1;i--){
suf[i] = suf[i+1]+a[i].se;
}
double ans = 0;
for(int i = 1,p = n;i<=n;i++){
if(i == 1||fabs(a[i].fi-a[i-1].fi)>eps){
while(p>i&&pre[i]/a[i].fi>suf[p]/(1-a[p].fi)) p--;
ans = max(ans,pre[i]+suf[p+1]-pre[i]/a[i].fi);
if(i>=p) break;
ans = max(ans,pre[i]+suf[p]-suf[p]/(1-a[p].fi));
}
}
cout<<fixed<<setprecision(10)<<ans<<'\n';
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t = 1;
//cin>>t;
while(t--){
solve();
}
return 0;
}
/*
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3812kb
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: 4040kb
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: 3812kb
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: 3904kb
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: 4036kb
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: 3944kb
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: 3828kb
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: 0ms
memory: 3872kb
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'