# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
954045 | blackslex | Balloons (CEOI11_bal) | C++17 | 2031 ms | 6120 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int n;
bool qrm;
struct line {
double m, c;
mutable double p;
line(double p) : p(p) {}
line(double m, double c) : m(m), c(c) {}
friend bool operator < (const line &l1, const line &l2) {return qrm ? l1.p < l2.p : l1.m < l2.m;}
};
struct convex:multiset<line> {
double div (double a, double b) {return a / b;}
bool ck (iterator x, iterator y) {
if (y == end()) return x->p = 1e18, 0;
if (x->m == y->m) return x->p = x->c >= y->c ? 1e18 : -1e18;
else x->p = div(x->c - y->c, y->m - x->m);
return x->p >= y->p;
}
void add (double m, double c) {
auto y = insert(line(m, c)), x = y++;
while (ck(x, y)) y = erase(y);
if ((y = x) != begin() && ck(--x, y)) ck(x, erase(y));
while ((y = x) != begin() && (--x)->p >= y->p) ck(x, erase(y));
}
double qr (int x) {
if (empty()) return 1e18;
qrm = 1; auto idx = lower_bound(x); qrm = 0;
return idx->m * x + idx->c;
}
} hull;
int main() {
scanf("%d", &n);
vector<int> x(n), r(n);
vector<double> dp(n);
// dp[i] = min {0<=j<i} {(x[i]-x[j])*(x[i]-x[j]) / 4*dp[j]}
// = min {0<=j<i} {x[i]*x[i]-2*x[i]*x[j]+x[j]^2 / 4*dp[j]}
// = x[i]*x[i] min {0<=j<i} {-2*x[i]*x[j]+x[j]*x[j] / 4*dp[j]}
// y=mx+c : m=-2*x[j] / 4*dp[j] c = x[j]*x[j] / 4*dp[j]
for (int i = 0; i < n; i++) scanf("%d %d", &x[i], &r[i]), dp[i] = (double) r[i];
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) dp[i] = min(dp[i], (double) 1.0 * (x[j] - x[i]) * (x[j] - x[i]) / (4.0 * dp[j]));
}
for (int i = 0; i < n; i++) printf("%.3lf\n", dp[i]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |