Submission #308090

# Submission time Handle Problem Language Result Execution time Memory
308090 2020-09-30T03:19:34 Z caoash Lightning Conductor (POI11_pio) C++17
81 / 100
1000 ms 11256 KB
#include <bits/stdc++.h> 
using namespace std;

using ll = long long;

using vi = vector<int>;
using vl = vector<ll>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair

const int MX = 500005;
const int MOD = (int) (1e9 + 7);
const ll INF = (ll) 1e18;

int a[MX];
int pre[MX], suf[MX];
int n;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        int j, k, c;
        if (i != 0) {
            for (j = i - 1, k = 1, c = 1; j >= 0; j -= k, k += 2, ++c) {
                suf[j] = max(suf[j], a[i] + c);
            }
        }
        if (i != n - 1) {
            for (j = i + 1, k = 1, c = 1; j < n; j += k, k += 2, ++c) {
                pre[j] = max(pre[j], a[i] + c);
            }
        }
    }
    for (int i = 1; i < n; ++i) {
        pre[i] = max(pre[i - 1], pre[i]);
    }
    for (int i = n - 2; i >= 0; --i) {
        suf[i] = max(suf[i + 1], suf[i]);
    }
    for (int i = 0; i < n; ++i) {
        cout << max(0, max(pre[i], suf[i]) - a[i]) << '\n';
    }
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 1408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 1400 KB Output is correct
2 Correct 48 ms 1408 KB Output is correct
3 Correct 48 ms 1656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 92 ms 2040 KB Output is correct
2 Correct 89 ms 1912 KB Output is correct
3 Correct 91 ms 2552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 308 ms 4156 KB Output is correct
2 Correct 298 ms 3960 KB Output is correct
3 Correct 296 ms 4680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 600 ms 8056 KB Output is correct
2 Correct 580 ms 5916 KB Output is correct
3 Correct 573 ms 8056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1044 ms 11256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1038 ms 8824 KB Time limit exceeded
2 Halted 0 ms 0 KB -