Submission #607456

# Submission time Handle Problem Language Result Execution time Memory
607456 2022-07-26T17:48:07 Z TH666 Balloons (CEOI11_bal) C++17
100 / 100
152 ms 12144 KB
#include <bits/stdc++.h>

#define int long long

using namespace std;

// #define MultipleCase       
void Solve(int tc) {
  int n;
  cin >> n;
  vector<pair<int,int>> vp(n);
  for (auto &[x, y] : vp) {
    cin >> x >> y;
  }
  vector<long double> ans(n);
  stack<pair<int, long double>> s;
  for (int i = 0; i < n; ++i) {
    auto [vx, vy] = vp[i];
    long double r = vy;
    while (!s.empty()) {
      auto [xp, rp] = s.top();
      long double cur = (long double) ((xp - vx) * (xp - vx)) / (4.0l * rp);
      r = min(r, cur);
      if (r >= rp) s.pop();
      else break;
    }
    ans[i] = r;
    s.push({vx, r});
  }
  cout << fixed << setprecision(5);
  for (auto &i : ans) {
    cout << i << '\n';
  }
}

int32_t main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt = 1, tc = 0;
#ifdef MultipleCase
  cin >> tt;
#endif
  while (tt--) Solve(++tc);
  return 0;
}
/*
c1 = (x1, r1), c2 = (x2, r)

(x1 - x2) ^ 2 + (r1 - r) ^ 2 == (r1 + r) ^ 2
=> (x1 - x2) ^ 2 = 4 * r1 * r
=> r = (x1 - x2) ^ 2 / (4 * r1)
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB 10 numbers
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB 2 numbers
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB 505 numbers
# Verdict Execution time Memory Grader output
1 Correct 3 ms 340 KB 2000 numbers
# Verdict Execution time Memory Grader output
1 Correct 17 ms 1344 KB 20000 numbers
# Verdict Execution time Memory Grader output
1 Correct 40 ms 3256 KB 50000 numbers
2 Correct 34 ms 2760 KB 49912 numbers
# Verdict Execution time Memory Grader output
1 Correct 88 ms 5196 KB 100000 numbers
# Verdict Execution time Memory Grader output
1 Correct 93 ms 5960 KB 115362 numbers
2 Correct 90 ms 7340 KB 119971 numbers
# Verdict Execution time Memory Grader output
1 Correct 138 ms 7484 KB 154271 numbers
2 Correct 128 ms 12132 KB 200000 numbers
# Verdict Execution time Memory Grader output
1 Correct 152 ms 9076 KB 200000 numbers
2 Correct 126 ms 12144 KB 199945 numbers