Submission #895004

# Submission time Handle Problem Language Result Execution time Memory
895004 2023-12-29T10:30:36 Z Jerseys Balloons (CEOI11_bal) C++17
10 / 100
31 ms 15904 KB
#ifdef LOCAL
#include "include/include.h"
#else
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
#endif
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> o_set;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
template<typename T> using minHeap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxHeap = priority_queue<T>;
#define int long long
#define all(s) s.begin(), s.end()
#define sz(s) (int) s.size()
#define testcases \
    cin >> tt;    \
    for (i = 1; i <= tt; i++)
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);                \
    cout.tie(NULL)
#define deb(a) cerr << #a << " = " << (a) << endl;
#define deb1(a)                                                        \
    cerr << #a << " = [ ";                                             \
    for (auto it = a.begin(); it != a.end(); it++) cerr << *it << " "; \
    cerr << "]" << endl;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
typedef vector<bool> vb;
const int INF = LONG_LONG_MAX;
const int M = 1e9 + 7;

void solve(int tt) {
    int n; cin >> n;
    vi pos(n), rad(n);
    for (int i = 0; i < n; i++) {
        cin >> pos[i] >> rad[i];
    }

    using ldbl = long double;
    using vldbl = vector<ldbl>;

    vi stk; // just indices lol
    vi range; // also a part of the stack
    vldbl ans(n, -1);
    auto push = [&] (int i) {
        while (not empty(stk) and (ans[stk.back()] < ans[i] or pos[i] > range[stk.back()])) {
            stk.pop_back();
            range.pop_back();
        }

        if (empty(stk)) {
            stk.push_back(i);
            range.push_back(1'000'000'000);
            return;
        }


        int j = stk.back();
        int L = pos[i], R = range[j];
        int ret = L;
        while (L <= R) {
            auto ok = [&] (int x) { // is x 'closer' to this circle or stk.back()
                return (ans[j] * (x - pos[i]) * (x - pos[i])) <= (ans[i] * (x - pos[j]) * (x - pos[j]));
            };
            int mid = L + (R - L) / 2;
            if (ok(mid)) {
                ret = mid;
                L = mid + 1;
            } else {
                R = mid - 1;
            }
        }
        stk.push_back(i);
        range.push_back(ret);
    };

    auto getAns = [&] (int x) {
        if (empty(stk)) return (ldbl) INF;

        // deb1(stk);
        // deb1(range);
        int L = 0, R = sz(stk) - 1;
        int ret = L;
        while (L <= R) {
            int mid = L + (R - L) / 2;
            if (range[mid] >= x) {
                ret = mid;
                L = mid + 1;
            } else {
                R = mid - 1;
            }
        }
        
        // deb(ret);
        // cout << "\n";
        int i = stk[ret];
        return ((x - pos[i]) * (x - pos[i])) / (4.0L * ans[ret]);
    };

    for (int i = 0; i < n; i++) {
        ans[i] = min(getAns(pos[i]), (ldbl) rad[i]);
        push(i);
    }

    for (int i = 0; i < n; i++) {
        cout << fixed << setprecision(3) << ans[i] << " ";
    }
    cout << "\n";
    
}

int32_t main() {
    fast;
    int tt = 1;
    int i = 1;
    // testcases
        solve(i);
}

Compilation message

bal.cpp: In function 'int32_t main()':
bal.cpp:119:9: warning: unused variable 'tt' [-Wunused-variable]
  119 |     int tt = 1;
      |         ^~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB 4th numbers differ - expected: '1.8420000000', found: '3.7600000000', error = '1.9180000000'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB 2 numbers
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB 7th numbers differ - expected: '0.0010000000', found: '9.0000000000', error = '8.9990000000'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 648 KB 80th numbers differ - expected: '33.0560000000', found: '34.0070000000', error = '0.9510000000'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 2136 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 12 ms 4444 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 18 ms 8416 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 20 ms 9556 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 26 ms 12476 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 31 ms 15904 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -