Submission #869201

# Submission time Handle Problem Language Result Execution time Memory
869201 2023-11-03T13:36:18 Z tvladm2009 Balloons (CEOI11_bal) C++17
40 / 100
2000 ms 9224 KB
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <cassert>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
#include <numeric>

using namespace std;

typedef long long ll;
typedef long double ld;
const int N = (int)2e5 + 7;
ld x[N], r[N], rad[N];
int n;

struct Circle {
        ld x;
        ld y;
        ld radius;
};

bool check(Circle a, Circle b) {
        ld d = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
        if (d <= (a.radius + b.radius) * (a.radius + b.radius)) {
                return false;
        }
        return true;
}

int main() {
#ifndef ONPC
        ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#else
        FILE* stream;
        freopen("input.txt", "r", stdin);
#endif
        cin >> n;
        for (int i = 1; i <= n; i++) {
                cin >> x[i] >> r[i];
        }
        rad[1] = r[1];
        vector<int> stk;
        stk.push_back(1);
        for (int i = 2; i <= n; i++) {
                ld best = r[i];
                for (auto &j : stk) {
                        ld lo = 0.0, hi = r[i], sol = 0.0;
                        for (int step = 1; step <= 100; step++) {
                                ld mi = (lo + hi) / 2;
                                if (check(Circle{rad[j], x[j], rad[j]}, Circle{mi, x[i], mi})) {
                                        lo = mi + 1;
                                        sol = mi;
                                }
                                else {
                                        hi = mi - 1;
                                }
                        }
                        best = min(best, sol);
                }
                {
                        int j = i - 1;
                        ld lo = 0.0, hi = r[i], sol = 0.0;
                        for (int step = 1; step <= 100; step++) {
                                ld mi = (lo + hi) / 2;
                                if (check(Circle{rad[j], x[j], rad[j]}, Circle{mi, x[i], mi})) {
                                        lo = mi + 1;
                                        sol = mi;
                                }
                                else {
                                        hi = mi - 1;
                                }
                        }
                        best = min(best, sol);
                }
                rad[i] = best;
                while (!stk.empty() && rad[i] >= rad[stk.back()]) {
                        stk.pop_back();
                }
                stk.push_back(i);
        }
        for (int i = 1; i <= n; i++) {
                cout << setprecision(10) << fixed << rad[i] << "\n";
        }
        return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB 10 numbers
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB 2 numbers
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4444 KB 505 numbers
# Verdict Execution time Memory Grader output
1 Correct 141 ms 4584 KB 2000 numbers
# Verdict Execution time Memory Grader output
1 Execution timed out 2067 ms 9224 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2037 ms 6916 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2059 ms 7156 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2033 ms 6908 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2013 ms 7188 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2060 ms 7764 KB Time limit exceeded
2 Halted 0 ms 0 KB -