Submission #842501

# Submission time Handle Problem Language Result Execution time Memory
842501 2023-09-03T01:34:11 Z NoLove Balloons (CEOI11_bal) C++14
100 / 100
691 ms 12060 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 pb push_back
#define all(v) (v).begin(), (v).end()
using pii = pair<int, int>;

const int INF = 2e9;
const double eps = 1e-6;
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(double ngang, double 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);
    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++) {
        std::cin >> x[i] >> r[i];
    }
    vector<int> s; // index of previous inflated balloon need to check, it will be decresing radius from top
    for (int b = 1; b <= n; b++) {
        f[b] = r[b];
        while (!s.empty() && f[b] >= f[s.back()]) {
            int a = s.back();
            db(b, a)
            f[b] = min(f[b], (x[b] - x[a]) * (x[b] - x[a]) / (4 * f[a]));
            if (f[b] >= f[s.back()])
                s.pop_back();
        }
        for (int a : s) {
            f[b] = min(f[b], (x[b] - x[a]) * (x[b] - x[a]) / (4 * f[a]));
        }
        s.push_back(b);
        cout << fixed << setprecision(4) << f[b] << "\n";
    }

}

Compilation message

bal.cpp: In function 'int32_t main()':
bal.cpp:43:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         freopen("hi.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB 10 numbers
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB 2 numbers
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB 505 numbers
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2396 KB 2000 numbers
# Verdict Execution time Memory Grader output
1 Correct 18 ms 2908 KB 20000 numbers
# Verdict Execution time Memory Grader output
1 Correct 274 ms 5732 KB 50000 numbers
2 Correct 142 ms 6392 KB 49912 numbers
# Verdict Execution time Memory Grader output
1 Correct 452 ms 6496 KB 100000 numbers
# Verdict Execution time Memory Grader output
1 Correct 638 ms 7048 KB 115362 numbers
2 Correct 341 ms 8788 KB 119971 numbers
# Verdict Execution time Memory Grader output
1 Correct 691 ms 7472 KB 154271 numbers
2 Correct 566 ms 11972 KB 200000 numbers
# Verdict Execution time Memory Grader output
1 Correct 300 ms 8620 KB 200000 numbers
2 Correct 558 ms 12060 KB 199945 numbers