# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
795400 | 2023-07-27T09:04:03 Z | nonono | Lightning Conductor (POI11_pio) | C++14 | 141 ms | 22904 KB |
#include <bits/stdc++.h> using namespace std; const int mxN = 5e5 + 10; int n; int h[mxN]; long double a[mxN], b[mxN]; deque<array<int, 3>> dq; long double eval(pair<int, int> a, int x) { return (long double)a.second + (long double)sqrt(x - a.first); } int slope(pair<int, int> x, pair<int, int> y) { if(x.second >= y.second) return n + 1; int low = y.first, right = n; low -- ; while(low <= right) { int mid = (low + right) / 2; if(sqrt(mid - x.first) + x.second >= sqrt(mid - y.first) + y.second) { low = mid + 1; } else { right = mid - 1; } } return low; } void ins(pair<int, int> newLine) { while(!dq.empty()) { dq.back()[2] = slope({dq.back()[0], dq.back()[1]}, newLine); if(dq.size() > 1 && dq[dq.size() - 2][2] >= dq.back()[2]) dq.pop_back(); else break ; } dq.push_back({newLine.first, newLine.second, n + 1}); } void solve(long double dp[]) { dq.clear(); for(int i = 1; i <= n; i ++) { ins({i, h[i]}); while(!dq.empty() && dq.front()[2] < i) dq.pop_front(); dp[i] = eval({dq.front()[0], dq.front()[1]}, i); } } int main() { #define taskname "" if (fopen(taskname".inp", "r")) { freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for(int i = 1; i <= n; i ++) cin >> h[i]; solve(a); reverse(h + 1, h + 1 + n); solve(b); reverse(h + 1, h + 1 + n); reverse(b + 1, b + 1 + n); for(int i = 1; i <= n; i ++) cout << (int)ceil(max(a[i], b[i])) - h[i] << "\n"; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 1620 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 2524 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 2900 KB | Output is correct |
2 | Correct | 13 ms | 2776 KB | Output is correct |
3 | Correct | 17 ms | 3112 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 4224 KB | Output is correct |
2 | Correct | 25 ms | 4176 KB | Output is correct |
3 | Correct | 25 ms | 4672 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 62 ms | 9392 KB | Output is correct |
2 | Correct | 60 ms | 9276 KB | Output is correct |
3 | Correct | 61 ms | 9896 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 102 ms | 16092 KB | Output is correct |
2 | Correct | 91 ms | 14088 KB | Output is correct |
3 | Correct | 94 ms | 16220 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 141 ms | 22836 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 139 ms | 20400 KB | Output is correct |
2 | Correct | 132 ms | 19824 KB | Output is correct |
3 | Correct | 133 ms | 22904 KB | Output is correct |