QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#773121 | #8037. Gambler's Ruin | Andeviking | WA | 3550ms | 111432kb | C++20 | 3.3kb | 2024-11-23 01:12:04 | 2024-11-23 01:12:05 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define range(x) (x).begin(), (x).end()
// using __float128 = ANS_TYPE;
using ANS_TYPE = __float128;
vector<long double> p;
vector<int> c;
vector<ANS_TYPE> ck, rck;
vector<ll> sum, rsum;
int n;
const ANS_TYPE EPS = 1e-18L;
ANS_TYPE f(ANS_TYPE x, ANS_TYPE y)
{
ll sx = 0, sy = 0;
int pos = upper_bound(range(ck), x, [](const auto &a, const auto &b) {
return b - a > EPS;
}) -
ck.begin();
if (pos - 1 >= int(sum.size()))
sx = sum.back();
else if (pos)
sx = sum[pos - 1];
// cout << pos << '\n';
// cout << rck.size() << '\n';
pos = upper_bound(range(rck) - pos, y, [](const auto &a, const auto &b) {
return b - a > EPS;
}) -
rck.begin();
if (pos - 1 >= int(rsum.size()))
sy = rsum.back();
else if (pos)
sy = rsum[pos - 1];
// cout << pos << '\n';
// cout << sx << ' ' << sy << ' ' << x << ' ' << y << ' ' << sx + sy - max(sx * x, sy * y) << '\n';
// if (sx + sy - max(sx * x, sy * y) > 15)
// cout << x << ' ' << y << ' ' << sx << ' ' << sy << '\n';
return sx + sy - max(sx * x, sy * y);
}
ANS_TYPE get(ANS_TYPE x)
{
ANS_TYPE l = 0, r = 1500010;
ANS_TYPE lans = f(x, l), rans = f(x, r);
ANS_TYPE ans = max(lans, rans);
for (int _ = 0; _ < 1000; ++_) {
ANS_TYPE lmid = l + (r - l) / 3;
ANS_TYPE rmid = r - (r - l) / 3;
lans = f(x, lmid), rans = f(x, rmid);
ans = max(lans, rans);
if (lans - rans >= EPS)
r = rmid;
else
l = lmid;
}
// cout << x << ' ' << l << ' ' << ans << '\n';
return ans;
}
void solve()
{
cin >> n;
p.resize(n + 5);
c.resize(n + 5);
for (int i = 1; i <= n; ++i) {
cin >> p[i] >> c[i];
p[i] = roundl(p[i] * 1000000);
}
vector<pair<ANS_TYPE, int>> ckk;
for (int i = 1; i <= n; ++i)
ckk.emplace_back(p[i], c[i]);
sort(range(ckk));
for (const auto &[a, b] : ckk) {
rck.push_back(1000000.L / (1000000 - a));
rsum.push_back(b);
if (rsum.size() > 1)
rsum.back() += rsum.end()[-2];
}
reverse(range(ckk));
for (const auto &[a, b] : ckk) {
ck.push_back(1000000.L / a);
sum.push_back(b);
if (sum.size() > 1)
sum.back() += sum.end()[-2];
}
// for (const auto &c : ck)
// cout << c << ' ';
// cout << '\n';
ANS_TYPE l = 0, r = 1500010;
ANS_TYPE lans = get(l), rans = get(r);
ANS_TYPE ans = max(lans, rans);
for (int _ = 0; _ < 1000; ++_) {
ANS_TYPE lmid = l + (r - l) / 3;
ANS_TYPE rmid = r - (r - l) / 3;
lans = get(lmid), rans = get(rmid);
ans = max(lans, rans);
if (lans - rans >= EPS)
r = rmid;
else
l = lmid;
}
// cout << l << '\n';
// cout << f(1 / .6L, 1.9) << '\n';
// cout << get(1 / .6L) << '\n';
cout << fixed << setprecision(10) << (long double)ans << '\n';
// cout << f(0, 0) << '\n';
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T = 1;
while (T--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 665ms
memory: 3864kb
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: 724ms
memory: 3896kb
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: 527ms
memory: 3900kb
input:
1 0 1
output:
-0.0000000000
result:
ok found '-0.0000000', expected '0.0000000', error '0.0000000'
Test #4:
score: 0
Accepted
time: 455ms
memory: 3916kb
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: 477ms
memory: 3848kb
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: 635ms
memory: 3920kb
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: 671ms
memory: 3896kb
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: 646ms
memory: 3860kb
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: 655ms
memory: 3948kb
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: 658ms
memory: 3916kb
input:
2 0 1000000000 0.000001 1
output:
1.0000000010
result:
ok found '1.0000000', expected '1.0000000', error '0.0000000'
Test #11:
score: -100
Wrong Answer
time: 3550ms
memory: 111432kb
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 ...
output:
85717936612193.0288619995
result:
wrong answer 1st numbers differ - expected: '85718080941203.0156250', found: '85717936612193.0312500', error = '0.0000017'