답안 #954045

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
954045 2024-03-27T07:04:28 Z blackslex Balloons (CEOI11_bal) C++17
60 / 100
2000 ms 6120 KB
#include<bits/stdc++.h>

using namespace std;

int n;
bool qrm;

struct line {
    double m, c;
    mutable double p;
    line(double p) : p(p) {}
    line(double m, double c) : m(m), c(c) {}
    friend bool operator < (const line &l1, const line &l2) {return qrm ? l1.p < l2.p : l1.m < l2.m;}
};

struct convex:multiset<line> {
    double div (double a, double b) {return a / b;}
    bool ck (iterator x, iterator y) {
        if (y == end()) return x->p = 1e18, 0;
        if (x->m == y->m) return x->p = x->c >= y->c ? 1e18 : -1e18;
        else x->p = div(x->c - y->c, y->m - x->m);
        return x->p >= y->p;
    }
    void add (double m, double c) {
        auto y = insert(line(m, c)), x = y++;
        while (ck(x, y)) y = erase(y);
        if ((y = x) != begin() && ck(--x, y)) ck(x, erase(y));
        while ((y = x) != begin() && (--x)->p >= y->p) ck(x, erase(y));
    }
    double qr (int x) {
        if (empty()) return 1e18;
        qrm = 1; auto idx = lower_bound(x); qrm = 0;
        return idx->m * x + idx->c;
    }
} hull;

int main() {
    scanf("%d", &n);
    vector<int> x(n), r(n);
    vector<double> dp(n);
    // dp[i] = min {0<=j<i} {(x[i]-x[j])*(x[i]-x[j]) / 4*dp[j]}
    // = min {0<=j<i} {x[i]*x[i]-2*x[i]*x[j]+x[j]^2 / 4*dp[j]}
    // = x[i]*x[i] min {0<=j<i} {-2*x[i]*x[j]+x[j]*x[j] / 4*dp[j]}
    // y=mx+c : m=-2*x[j] / 4*dp[j]  c = x[j]*x[j] / 4*dp[j]
    for (int i = 0; i < n; i++) scanf("%d %d", &x[i], &r[i]), dp[i] = (double) r[i];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < i; j++) dp[i] = min(dp[i], (double) 1.0 * (x[j] - x[i]) * (x[j] - x[i]) / (4.0 * dp[j]));
    }
    for (int i = 0; i < n; i++) printf("%.3lf\n", dp[i]);
}

Compilation message

bal.cpp: In member function 'bool convex::ck(std::multiset<line>::iterator, std::multiset<line>::iterator)':
bal.cpp:20:39: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   20 |         if (x->m == y->m) return x->p = x->c >= y->c ? 1e18 : -1e18;
      |                                  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bal.cpp: In function 'int main()':
bal.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
bal.cpp:45:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |     for (int i = 0; i < n; i++) scanf("%d %d", &x[i], &r[i]), dp[i] = (double) r[i];
      |                                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB 10 numbers
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB 2 numbers
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 504 KB 505 numbers
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 348 KB 2000 numbers
# 결과 실행 시간 메모리 Grader output
1 Correct 318 ms 1112 KB 20000 numbers
# 결과 실행 시간 메모리 Grader output
1 Correct 1956 ms 2180 KB 50000 numbers
2 Correct 1933 ms 2440 KB 49912 numbers
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2031 ms 3416 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2005 ms 3904 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2023 ms 5008 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2005 ms 6120 KB Time limit exceeded
2 Halted 0 ms 0 KB -