Submission #1045133

# Submission time Handle Problem Language Result Execution time Memory
1045133 2024-08-05T17:17:58 Z nmts Balloons (CEOI11_bal) C++17
100 / 100
141 ms 1872 KB
#include <bits/stdc++.h>

#define file(name) freopen(name".inp" , " r " , stdin);freopen(name".out" , " w " , stdout);
#define faster    ios_base :: sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ;
#define pii pair < int , int >
#define fi first
#define se second
#define mii map< int , int>
#define reset(a,val) memset(a ,val , sizeof(a) )
#define count_bit(i) __builtin_popcountll(i) 
#define mask(i) ((1LL << (i)))  
#define status(x, i) (((x) >> (i)) & 1)  
#define set_on(x, i) ((x) | mask(i)) 
#define set_off(x, i) ((x) & ~mask(i))
#define endl '\n'    
#define ll long long
#define double long double
const int maxn = 1e6 + 6;
const int mod= 1e9 + 7;
const ll INFLL= 3e18 + 5;
const int INF = 1e9 + 5 ;
const int LOG = 20 ;


template <class T> inline T sqr(T x) { return x * x; };

template <class T> inline int Power(T x, int y) 

{ if (!y) return 1; if (y & 1) return sqr(Power(x, y / 2)) % mod * x % mod; return sqr(Power(x, y / 2)) % mod; }

template<class T> bool minimize(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool maximize(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

inline int gcd(int x, int y) 
{ return y ? gcd(y , x % y) : x;}

inline int lcm(int x, int y) { return x * y / gcd(x, y); }

using namespace std;

double calc(double ax , double ar , double bx)
{
    return (ax - bx) * (ax - bx) / (4.0 * ar);
}
int n;
stack<pair<double, double>> s;
void solve()
{

    cin >> n ;

    for (int i = 1 ; i <= n ; ++i)
        {
            double x , r ; cin >> x >> r;
            double maxr = r;
            while (!s.empty())
                {
                    minimize(maxr , calc(s.top().fi , s.top().se , x));

                    if (maxr >= s.top().se)
                        {
                            s.pop();
                        }
                    else break;

                }       
            
            s.push({x , maxr});
            cout << setprecision(3) << fixed << maxr << endl;
        }


}


int32_t main()
{
    faster;
    // file("txt");
    // int t ; cin >> t ; while (t--)
    solve();
    return 0;
} 
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB 10 numbers
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB 2 numbers
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB 505 numbers
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB 2000 numbers
# Verdict Execution time Memory Grader output
1 Correct 19 ms 604 KB 20000 numbers
# Verdict Execution time Memory Grader output
1 Correct 31 ms 1084 KB 50000 numbers
2 Correct 30 ms 604 KB 49912 numbers
# Verdict Execution time Memory Grader output
1 Correct 59 ms 1448 KB 100000 numbers
# Verdict Execution time Memory Grader output
1 Correct 71 ms 1616 KB 115362 numbers
2 Correct 64 ms 1044 KB 119971 numbers
# Verdict Execution time Memory Grader output
1 Correct 93 ms 1872 KB 154271 numbers
2 Correct 131 ms 1616 KB 200000 numbers
# Verdict Execution time Memory Grader output
1 Correct 117 ms 1872 KB 200000 numbers
2 Correct 141 ms 1668 KB 199945 numbers