Submission #683047

#TimeUsernameProblemLanguageResultExecution timeMemory
683047omikron123Balloons (CEOI11_bal)C++14
20 / 100
236 ms10156 KiB
// https://oj.uz/problem/view/CEOI11_bal #include <cstdio> #include <algorithm> #include <functional> #include <vector> #include <cstring> #include <stack> using namespace std; typedef long long ll; /* 1. y[i] = min( (x[i]-x[j])^2 / (4*y[j]) ) 2. 检查每一个之前的气球导致O(n^2),会TLE. 3. 我们注意到: a. 对于一个气球(y[i],x[i]),任何比这个气球位置更左,大小更小的气球都是不会和将来的气球接触到的。 b. 如果i碰到一个左侧更大的气球j,则肯定不会碰到j左侧更大的气球。 4. 所以问题变成了nearest larger value的问题,我们要维护一个直径单调减的气球的stack。 5. 每次新增气球时,从stack顶开始计算y[i],如果比栈顶大,就pop再计算。如果小于等于栈顶,则这个大小合适。 */ int n; // 2e5 int x[200005], r[200005]; double ans[200005]; stack<pair<double,int>> st; // (radius, x), radius decreasing, x increasing int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d %d", &x[i], &r[i]); for (int i = 0; i < n; i++) { double y = r[i]; while (!st.empty()) { y = min(y, (x[i]-st.top().second)*(x[i]-st.top().second) / st.top().first / 4); if (y > st.top().first) st.pop(); else break; } st.push({y, x[i]}); ans[i] = y; } for (int i = 0; i < n; i++) printf("%lf\n", ans[i]); return 0; }

Compilation message (stderr)

bal.cpp: In function 'int main()':
bal.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
bal.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         scanf("%d %d", &x[i], &r[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...