QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#728933 | #8037. Gambler's Ruin | DFLMKWR | WA | 1ms | 3936kb | C++20 | 1.7kb | 2024-11-09 16:13:13 | 2024-11-09 16:13:31 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) cerr << #x << "=" << x << "\n"
#define MULTI int _; cin >> _; while (_--)
#define int long long
#define ull unsigned long long
typedef long long ll;
const int N = 1e6 + 5, INF = 0x3f3f3f3f3f3f3f3f;
struct Node {
double p;
int c;
bool operator<(const Node &x) const {
return p > x.p;
}
};
void solve() {
int n;
cin >> n;
vector<Node> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i].p >> a[i].c;
}
sort(a.begin(), a.end());
vector<double> sy(n + 1);
double sx = 0;
for (int i = n - 1; i >= 0; i--) {
sy[i] = sy[i + 1] + a[i].c;
}
int fg1 = -1, fg0 = n;
for (int i = 0; i < n; i++) {
if (a[i].p == 1) {
fg1 = max(fg1, i);
} else if (a[i].p == 0) {
fg0 = min(fg0, i);
}
}
double res = 0;
for (int i = 0; i < min(n, fg0); i++) {
double x = 1.0 / a[i].p;
sx += a[i].c;
if (i != min(n, fg0) - 1 && a[i].p == a[i + 1].p) continue;
int l = max(i + 1, fg1 + 1), r = n - 1, lm, rm;
double ans = -INF;
function<double(int)> check = [&](int mid) -> double {
return sx + sy[mid] - max(sx * x, sy[mid] * 1.0 / (1.0 - a[mid].p));
};
if (l == r) {
res = max(res, check(l));
}
while (l < r) {
lm = l + (r - l) / 3;
rm = r - (r - l) / 3;
double ck1 = check(lm), ck2 = check(rm);
if (ck1 < ck2) {
ans = max(ans, ck2);
r = rm - 1;
} else {
ans = max(ans, ck1);
l = lm + 1;
}
}
res = max(res, ans);
}
cout << fixed << setprecision(10);
cout << res << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3872kb
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: 3824kb
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: 3904kb
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: 3808kb
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: 3824kb
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: 3820kb
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: 3936kb
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'