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;
#define cIO ios_base::sync_with_stdio(0);cin.tie(0)
#define fileIO(x) ifstream fin(string(x)+".in"); ofstream fout(string(x)+".out")
#define ll long long
#define ld long double
#define sz(x) (int) (x).size()
#define v vector
#define pb push_back
ll bal[200001][2];//[0]=x, [1]=r
ld ans[200001] = {};
int n;
ld get_rad(int b2, int b1)//b2 is the balloon we want to inflate, b1 is the balloon we want to intersect
{
ld rad = (ld)(bal[b2][0] - bal[b1][0]);
return rad * rad / (ld)ans[b1] / 4;
}
int main()
{
cin >> n;
for (int i = 0; i <= n-1; i++)
{
cin >> bal[i][0] >> bal[i][1];
}
stack<ll> stk;//stores the indices of the big bal we need to consider
ans[0] = (ld)bal[0][1];
stk.push(0);
for (int i = 1; i <= n - 1; i++)
{
ld next_rad = min((ld)bal[i][1], get_rad(i, stk.top()));//if this value is less than the radius of the top balloon, we can continue
while (!stk.empty()&&next_rad > ans[stk.top()])
{
stk.pop();
if (stk.empty()) break;
next_rad = min(next_rad, get_rad(i, stk.top()));
}
stk.push(i);
ans[i] = next_rad;
}
for (int i = 0; i <= n - 1; i++) cout << ans[i] << "\n";
}
# | 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... |