Submission #356812

# Submission time Handle Problem Language Result Execution time Memory
356812 2021-01-23T17:51:37 Z jnk Balloons (CEOI11_bal) C++17
100 / 100
159 ms 11756 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

double x[200005], r[200005], res[200005];

int main(){
    
    int n; cin >> n;
    for(int i = 0; i < n; i++)
        scanf("%lf %lf", &x[i], &r[i]);

    res[0] = r[0];
    stack<pair<double,double>> st;
    st.push(make_pair(x[0], res[0]));

    for(int i = 1; i < n; i++){
        double ra = r[i];
        while(!st.empty()){
            auto p = st.top();
            double xdif = x[i] - p.first;
            double r = r - p.second;
            ra = min(ra, xdif * xdif / (4 * p.second));
            if(ra > p.second) st.pop();
            else break;
        }
        res[i] = ra;
        st.push(make_pair(x[i], res[i]));
    }

    for(int i = 0; i < n; i++)
        printf("%.3f\n", res[i]);

	return 0;
}

Compilation message

bal.cpp: In function 'int main()':
bal.cpp:31:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   31 |     for(int i = 0; i < n; i++)
      |     ^~~
bal.cpp:34:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   34 |  return 0;
      |  ^~~~~~
bal.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 |         scanf("%lf %lf", &x[i], &r[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB 10 numbers
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB 2 numbers
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB 505 numbers
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB 2000 numbers
# Verdict Execution time Memory Grader output
1 Correct 17 ms 980 KB 20000 numbers
# Verdict Execution time Memory Grader output
1 Correct 41 ms 2156 KB 50000 numbers
2 Correct 37 ms 2284 KB 49912 numbers
# Verdict Execution time Memory Grader output
1 Correct 90 ms 3692 KB 100000 numbers
# Verdict Execution time Memory Grader output
1 Correct 110 ms 4344 KB 115362 numbers
2 Correct 89 ms 7276 KB 119971 numbers
# Verdict Execution time Memory Grader output
1 Correct 132 ms 5464 KB 154271 numbers
2 Correct 144 ms 7916 KB 200000 numbers
# Verdict Execution time Memory Grader output
1 Correct 159 ms 6636 KB 200000 numbers
2 Correct 151 ms 11756 KB 199945 numbers