이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44
using namespace std;
const int MAXN = (int) 5e5 + 5;
int pref[MAXN + 1], suff[MAXN + 1];
int h[MAXN + 1], sq[1000];
int main() {
//ifstream cin("B.in");
//ofstream cout("B.out");
int i, n;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n;
for(i = 1; i <= n; i++) {
cin >> h[i];
}
for(i = 1; i < 1000; i++) {
sq[i] = i * i;
}
for(int j = 1; j <= n; j++) {
int pos;
pref[j] = max(pref[j], h[j]);
for(i = 1; j + sq[i - 1] < n; i++) {
pos = j + sq[i - 1] + 1;
pref[pos] = max(pref[pos], h[j] + i);
}
suff[j] = max(suff[j], h[j]);
for(i = 1; j - sq[i - 1] - 1 >= 1; i++) {
pos = j - sq[i - 1] - 1;
suff[pos] = max(suff[pos], h[j] + i);
}
}
for(i = 1; i <= n; i++) {
pref[i] = max(pref[i], pref[i - 1]);
}
for(i = n; i >= 1; i--) {
suff[i] = max(suff[i + 1], suff[i]);
}
for(i = 1; i <= n; i++) {
cout << max(pref[i], suff[i]) - h[i] << "\n";
}
//cin.close();
//cout.close();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |