Submission #960780

#TimeUsernameProblemLanguageResultExecution timeMemory
960780Zero_OPLightning Conductor (POI11_pio)C++14
72 / 100
1076 ms41820 KiB
#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]; } vector<int> lg(n + 1); lg[1] = 0; for(int i = 2; i <= n; ++i){ lg[i] = lg[i >> 1] + 1; } 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 = lg[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 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...
#Verdict Execution timeMemoryGrader output
Fetching results...