Submission #960778

# Submission time Handle Problem Language Result Execution time Memory
960778 2024-04-11T03:35:01 Z Zero_OP Lightning Conductor (POI11_pio) C++17
72 / 100
1000 ms 44368 KB
#include<bits/stdc++.h>

using namespace std;

int ceil_sqrt(int n){
    int x = sqrt(n);
    while(x * x < n) ++x;
    return x;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n; cin >> n;
    vector<int> h(n);
    vector<vector<int>> st;
    st.push_back(vector<int>(n));
    for(int i = 0; i < n; ++i){
        cin >> h[i];
        st[0][i] = h[i];
    }

    for(int i = 1; (1 << i) <= n; ++i){
        st.push_back(vector<int>(n - (1 << i) + 1));
        for(int j = 0; j + (1 << i) <= n; ++j){
            st[i][j] = max(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
        }
    }

    auto max_range = [&](int l, int r){
        int b = 31 - __builtin_clz(r - l  + 1);
        return max(st[b][l], st[b][r - (1 << b) + 1]);
    };

    vector<int> p(n);
    for(int i = 0; i < n; ++i){ 
        if(i != 0){
            int B = ceil_sqrt(i);
            for(int k = 1; k <= B; ++k){
                p[i] = max(p[i], max_range(max(0, i - k * k), i - (k - 1) * (k - 1) - 1) + k - h[i]);
            }
        }

        if(i != n - 1){
            int B = ceil_sqrt(n - 1 - i);
            for(int k = 1; k <= B; ++k){
                p[i] = max(p[i], max_range(i + (k - 1) * (k - 1) + 1, min(n - 1, i + k * k)) + k - h[i]);
            }
        }
    }

    for(int i = 0; i < n; ++i){
        cout << p[i] << '\n';
    }
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 2556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 4468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 5688 KB Output is correct
2 Correct 132 ms 5188 KB Output is correct
3 Correct 112 ms 5460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 220 ms 8528 KB Output is correct
2 Correct 211 ms 8460 KB Output is correct
3 Correct 205 ms 8596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 742 ms 20820 KB Output is correct
2 Correct 782 ms 20140 KB Output is correct
3 Correct 832 ms 20216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1016 ms 30580 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1047 ms 44280 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1025 ms 44368 KB Time limit exceeded
2 Halted 0 ms 0 KB -