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;
double ck(double posi, double posj, double ri){
int on = ((posj-posi)*(posj-posi));
//cout << posi << " " << posj << " " << ri << " " << on << " " << (1.0*on)/(4.0*ri) << "\n\n";
return (1.0*on)/(4.0*ri);
}
int main() {
int n;
cin >> n;
pair<double,double> bal[n];
for (int i = 0; i<n; i++){
cin >> bal[i].first >> bal[i].second;
}
stack<pair<int,double>> s;
//index, how much it is inflated
//monotonic stack
vector<double> ans(n);
ans[0] = bal[0].second;
s.push({0,bal[0].second});
for (int i = 1; i<n; i++){
ans[i] = bal[i].second;
if (!s.empty()){
pair<int,double> a = s.top();
/*while ((!s.empty()) && (ck(a.first,bal[i].first,a.second) >= bal[i].second)){
s.pop();
if (!s.empty()){
a = s.top();
}
}*/
while (!s.empty()){
double v = ck(bal[a.first].first, bal[i].first, a.second);
ans[i] = min(ans[i],v);
if (v > ans[a.first]){
s.pop();
if (!s.empty()){
a = s.top();
}
}
else{
break;
}
}
}
if (!s.empty()){
pair<int,double> a = s.top();
ans[i] = min(ck(bal[a.first].first,bal[i].first,a.second),bal[i].second);
}
s.push({i,ans[i]});
}
for (auto x : ans){
cout << fixed << setprecision(3) << x << '\n';
}
return 0;
}
# | 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... |