#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);
for(int i = 0; i < n; ++i){
cin >> h[i];
}
vector<int> p(n);
for(int i = 0, cur = 0; i < n; ++i){
for(int k = 1; i - (k - 1) * (k - 1) - 1 >= 0; ++k){
cur = max(cur, h[i - (k - 1) * (k - 1) - 1] + k);
}
p[i] = max(p[i], cur);
}
for(int i = n - 1, cur = 0; i >= 0; --i){
for(int k = 1; i + (k - 1) * (k - 1) + 1 < n; ++k){
cur = max(cur, h[i + (k - 1) * (k - 1) + 1] + k);
}
p[i] = max(p[i], cur);
}
for(int i = 0; i < n; ++i){
cout << max(0, p[i] - h[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 |
0 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 |
12 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
1596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
1876 KB |
Output is correct |
2 |
Correct |
34 ms |
1104 KB |
Output is correct |
3 |
Correct |
33 ms |
1644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
2388 KB |
Output is correct |
2 |
Correct |
64 ms |
2448 KB |
Output is correct |
3 |
Correct |
59 ms |
2640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
207 ms |
5484 KB |
Output is correct |
2 |
Correct |
220 ms |
5016 KB |
Output is correct |
3 |
Correct |
198 ms |
5092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
395 ms |
10028 KB |
Output is correct |
2 |
Correct |
401 ms |
7956 KB |
Output is correct |
3 |
Correct |
376 ms |
8548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
668 ms |
14036 KB |
Output is correct |
2 |
Correct |
661 ms |
11032 KB |
Output is correct |
3 |
Correct |
646 ms |
12104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
639 ms |
11788 KB |
Output is correct |
2 |
Correct |
666 ms |
11208 KB |
Output is correct |
3 |
Correct |
691 ms |
12104 KB |
Output is correct |