# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
795381 | 2023-07-27T08:47:34 Z | nonono | Lightning Conductor (POI11_pio) | C++14 | 146 ms | 25752 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; 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 | 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 | Incorrect | 8 ms | 1620 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 13 ms | 2536 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 2860 KB | Output is correct |
2 | Correct | 9 ms | 2844 KB | Output is correct |
3 | Correct | 16 ms | 3156 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 4180 KB | Output is correct |
2 | Correct | 26 ms | 4100 KB | Output is correct |
3 | Correct | 25 ms | 4756 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 61 ms | 9356 KB | Output is correct |
2 | Correct | 57 ms | 9240 KB | Output is correct |
3 | Correct | 57 ms | 9968 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 102 ms | 16076 KB | Output is correct |
2 | Correct | 89 ms | 14016 KB | Output is correct |
3 | Correct | 90 ms | 16204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 146 ms | 22812 KB | Output is correct |
2 | Correct | 128 ms | 19812 KB | Output is correct |
3 | Correct | 130 ms | 22948 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 138 ms | 20348 KB | Output is correct |
2 | Correct | 129 ms | 24800 KB | Output is correct |
3 | Correct | 130 ms | 25752 KB | Output is correct |