Submission #446156

#TimeUsernameProblemLanguageResultExecution timeMemory
446156abitpalBalloons (CEOI11_bal)C++14
100 / 100
1911 ms10244 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const ll MOD = 1e9 + 7; int di[] = {1, 0, -1, 0}, dj[] = {0, 1, 0, -1}; unsigned ll gcd(unsigned ll a ,unsigned ll b){ if(b==0) return a; a%=b; return gcd(b,a); } unsigned ll lcm(unsigned ll a ,unsigned ll b){ return (a /(gcd(a, b))) * b; } ll binpow(ll a, ll b, ll m){ a %= m; ll ans = 1; while (b > 0){ if (b%2){ ans = ans * a % m; } a = a * a % m; b /= 2; } return ans % m; } int e[2000]; int get(int x) {return e[x] < 0 ? x : e[x] = get(e[x]); } int size(int x) {return -e[get(x)]; } int unite(int a, int b){ if (get(a) == get(b)) return 0; a = get(a); b = get(b); if (e[a] > e[b]) swap(a, b); e[a] += e[b]; e[b] = a; return 1; } // dp[i] - number of ways to produce the sum of i, using the values on a dice // dp[i] += dp[i-1] + dp[i-2] .. + dp[i-6] double calc(pair<double, double> a, double b){ double dif = pow(abs(a.first - b), 2); return (dif/(4 * a.second)); } int main(){ int n; cin >> n; pair<double,double> ar[n]; for (int i = 0; i < n; i++){ cin >> ar[i].first >> ar[i].second; } double ans[n]; ans[0] = ar[0].second; vector<pair<double, double>> v; v.push_back({ar[0].first, ar[0].second}); for (int i = 1; i < n; i++){ double cur = ar[i].second; double x = ar[i].first; for (auto i : v){ cur = min(cur, calc(i, x)); } if (cur != ar[i].second) while (!v.empty() && calc(v.back(), x) != cur) v.pop_back(); while (!v.empty() && v.back().second <= cur) v.pop_back(); v.push_back({x, cur}); ans[i] = cur; } for (int i = 0; i < n; i++){ cout << fixed; cout << setprecision(3); cout << ans[i] << 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...