# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
491991 |
2021-12-05T09:45:17 Z |
clams |
Balloons (CEOI11_bal) |
C++17 |
|
208 ms |
14880 KB |
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = long double;
#define int long long
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<db> x(n + 1), r(n + 1);
for(int i = 1; i <= n; i++) {
cin >> x[i] >> r[i];
}
// distance between centers of 2 balloons
// sqrt(abs(x2 - x1)**2 + abs(r2 - r1)**2)
// must be equal to (r1 + r2)
// => (x2 - x1)**2 + abs(r2 - r1)**2 == (r1 + r2)**2
// => (x2**2 + x1**2 - 2x1x2) + (r2**2 + r1**2 - 2r1r2) = r1**2 + r2**2 + 2r1r2
// => (x2 - x1)**2 = 4r1r2
// => r2 = ((x2 - x1)**2) / (4r1)
vector<db> ans(n + 1);
stack<pair<db, db>> st;
for(int i = 1; i <= n; i++) {
if(st.empty()) {
st.push({x[i], r[i]});
ans[i] = r[i];
continue;
}
while(!st.empty()) {
pair<db, db> cur = st.top();
r[i] = min(r[i], (x[i] - cur.first) * (x[i] - cur.first) / (4 * cur.second));
if(r[i] >= cur.second) st.pop();
else break;
}
st.push({x[i], r[i]});
ans[i] = r[i];
}
for(int i = 1; i <= n; i++) {
cout << fixed << setprecision(3) << ans[i] << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
10 numbers |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
2 numbers |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
505 numbers |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
388 KB |
2000 numbers |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
1440 KB |
20000 numbers |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
3364 KB |
50000 numbers |
2 |
Correct |
49 ms |
3912 KB |
49912 numbers |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
6132 KB |
100000 numbers |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
135 ms |
7016 KB |
115362 numbers |
2 |
Correct |
132 ms |
9044 KB |
119971 numbers |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
172 ms |
9244 KB |
154271 numbers |
2 |
Correct |
189 ms |
14768 KB |
200000 numbers |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
208 ms |
11420 KB |
200000 numbers |
2 |
Correct |
190 ms |
14880 KB |
199945 numbers |