Submission #954045

#TimeUsernameProblemLanguageResultExecution timeMemory
954045blackslexBalloons (CEOI11_bal)C++17
60 / 100
2031 ms6120 KiB
#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)

bal.cpp: In member function 'bool convex::ck(std::multiset<line>::iterator, std::multiset<line>::iterator)':
bal.cpp:20:39: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   20 |         if (x->m == y->m) return x->p = x->c >= y->c ? 1e18 : -1e18;
      |                                  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bal.cpp: In function 'int main()':
bal.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
bal.cpp:45:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |     for (int i = 0; i < n; i++) scanf("%d %d", &x[i], &r[i]), dp[i] = (double) r[i];
      |                                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...