Submission #491991

#TimeUsernameProblemLanguageResultExecution timeMemory
491991clamsBalloons (CEOI11_bal)C++17
100 / 100
208 ms14880 KiB
#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 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...