Submission #1122234

#TimeUsernameProblemLanguageResultExecution timeMemory
1122234LeynaBalloons (CEOI11_bal)C++17
0 / 100
84 ms11084 KiB
#include <bits/stdc++.h> using namespace std; set<pair<float, int>> steigungen; set<pair<int, int>> endpunkt; vector<float> ende; vector<float> steigung; float max_r(float r1, float x1, float x2){ return ((x1-x2) * (x1-x2)) / (4 * r1); } int find_interval(int x1){ pair<int, int> interval = *lower_bound(endpunkt.begin(), endpunkt.end(), make_pair(x1, 0)); return interval.second; } float schnittstelle(float a1, float b1, float a2, float b2){ float a = b2 - b1; float b = 2*a2*b1 - 2*a1*b2; float c = b2*a1*a1 - b1*a2*a2; float radikand = sqrt(b*b - 4.0 * a * c); float x1 = (-b + radikand) / 2 * a; float x2 = (-b - radikand) / 2 * a; return max(x1, x2); } void del(int idx){ endpunkt.erase(endpunkt.find(make_pair(ende[idx], idx))); steigungen.erase(steigungen.find(make_pair(steigung[idx], idx))); } int main(){ int n; cin >> n; vector<int> x(n), r(n); for (int i=0; i<n; i++){ cin >> x[i] >> r[i]; } vector<float> res(n); res[0] = r[0]; //int last_idx = 0; ende.resize(n); steigung.resize(n); ende[0] = 1e9; steigungen.insert({4*res[0], 0}); endpunkt.insert({1e9, 0}); for (int i=1; i<n; i++){ int idx = find_interval(x[i]); res[i] = min(max_r(r[idx], x[idx], x[i]), (float)r[i]); //steigungen.erase(steigungen.end(), steigungen.upper_bound({4.0 * res[i], 0})); steigung[i] = res[i] * 4.0; // alle steileren aus steigungen UND endpunkten löschen while(steigungen.size() > 0 && (*steigungen.begin()).first <= steigung[i]){ int idx2 = (*steigungen.begin()).second; del(idx2); } if(steigungen.size() == 0){ steigungen.insert({res[i]*4.0, i}); endpunkt.insert({1e9, i}); continue; } float s = schnittstelle(x[idx], steigung[idx], x[i], res[i]*4); auto interval = lower_bound(endpunkt.begin(), endpunkt.end(), make_pair(x[i], 0)); while(endpunkt.size() > 0 && (*interval).second != find_interval(s)){ int idx2 = (*interval).second; interval++; del(idx2); } if(steigungen.size() == 0){ steigungen.insert({res[i]*4.0, i}); endpunkt.insert({1e9, i}); continue; } ende[i] = s; endpunkt.insert({ende[i], i}); steigungen.insert({steigung[i], i}); } for (float a : res) cout << fixed << setprecision(3) << a << endl; }
#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...