Submission #842488

# Submission time Handle Problem Language Result Execution time Memory
842488 2023-09-03T00:33:05 Z NoLove Balloons (CEOI11_bal) C++14
0 / 100
2000 ms 9044 KB
/**
 *    author : Lăng Trọng Đạt
 *    created: 2023-09-02
**/
#include <bits/stdc++.h>
using namespace std;
#ifndef LANG_DAT
#define db(...) ;
#endif // LANG_DAT
#define int int64_t
#define mp make_pair
#define f first
#define s second
#define pb push_back
#define all(v) (v).begin(), (v).end()
using pii = pair<int, int>;

const int INF = 2e9;
const double eps = 1e-5;
const int MAXN = 2e5 + 5;
int x[MAXN], r[MAXN],  id[MAXN]; // f[i]: final radius of balloon i
double f[MAXN];
int n;

inline double dist(int ngang, int doc) {
    return sqrt((double)ngang*ngang + doc*doc);
}

bool vaild(double radius, int pos, int adj) {
    double d =  dist(abs(pos - x[adj]), abs(radius - f[adj]));
    db(f[adj], radius, d, pos, x[adj])
    return f[adj] + radius <= d;
}

bool check(double radius, int pos, int i) {
    bool res = true;
    for (int j = i - 1; j > 0 && res; j--)
        res &= vaild(radius, pos, j);
    for (int j = i + 1; j <= n && res; j++)
        res &= vaild(radius, pos, j);
    return res;
}

int32_t main() {
    cin.tie(0)->sync_with_stdio(0);
    if (fopen("hi.inp", "r")) {
        freopen("hi.inp", "r", stdin);
//        freopen("hi.out", "w", stdout);
    }

    std::cin >> n;
    for (int i = 1; i <= n; i++) {
        id[i] = i;
        std::cin >> x[i] >> r[i];
    }
    sort(id + 1, id + n + 1, [](int& a, int& b) -> bool {return r[a] < r[b];});
    x[0] = -INF;
    x[n + 1] = INF;
    for (int i = 1; i <= n; i++) {
        double lo = 0, hi = r[id[i]], res = 0;
        while ((hi - lo) > eps) {
            double mid = (lo + hi) / 2;
            if (check(mid, x[id[i]], id[i])) {
                res = mid;
                lo = mid + eps;
            } else hi = mid - eps;
        }
        f[id[i]] = res;
        db(id[i], res)
    }

    for (int i = 1; i <= n; i++) {
        cout << fixed << setprecision(10) << f[i] << "\n";
    }
}

Compilation message

bal.cpp: In function 'int32_t main()':
bal.cpp:47:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         freopen("hi.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4444 KB 1st numbers differ - expected: '24.0000000000', found: '14.1896227964', error = '9.8103772036'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4444 KB 2nd numbers differ - expected: '252735385.4379999936', found: '252735385.4329085946', error = '0.0050913990'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 4444 KB 1st numbers differ - expected: '213.0000000000', found: '0.0000153916', error = '212.9999846084'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 265 ms 4612 KB 2nd numbers differ - expected: '122.0020000000', found: '122.0000107911', error = '0.0019892089'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2040 ms 5204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2024 ms 5468 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2033 ms 7048 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2043 ms 7252 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2028 ms 8276 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2036 ms 9044 KB Time limit exceeded
2 Halted 0 ms 0 KB -