Submission #795378

# Submission time Handle Problem Language Result Execution time Memory
795378 2023-07-27T08:42:45 Z nonono Lightning Conductor (POI11_pio) C++14
9 / 100
169 ms 27596 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(int(sqrt(mid - x.first)) + x.second >= int(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

pio.cpp: In function 'int main()':
pio.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
pio.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 1968 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 2984 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 3516 KB Output is correct
2 Correct 10 ms 3028 KB Output is correct
3 Incorrect 16 ms 3404 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 5196 KB Output is correct
2 Correct 25 ms 5160 KB Output is correct
3 Incorrect 28 ms 5216 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 61 ms 11624 KB Output is correct
2 Correct 62 ms 11236 KB Output is correct
3 Incorrect 57 ms 11212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 102 ms 19572 KB Output is correct
2 Correct 91 ms 17476 KB Output is correct
3 Incorrect 94 ms 18248 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 139 ms 27596 KB Output is correct
2 Correct 131 ms 24788 KB Output is correct
3 Incorrect 136 ms 25744 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 169 ms 25296 KB Output isn't correct
2 Halted 0 ms 0 KB -