Submission #308088

# Submission time Handle Problem Language Result Execution time Memory
308088 2020-09-30T03:17:19 Z caoash Lightning Conductor (POI11_pio) C++14
81 / 100
1000 ms 11384 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 384 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 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 1400 KB Output is correct
2 Correct 46 ms 1400 KB Output is correct
3 Correct 48 ms 1656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 93 ms 1912 KB Output is correct
2 Correct 92 ms 1912 KB Output is correct
3 Correct 95 ms 2552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 303 ms 4220 KB Output is correct
2 Correct 307 ms 3960 KB Output is correct
3 Correct 302 ms 4600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 595 ms 7928 KB Output is correct
2 Correct 580 ms 9592 KB Output is correct
3 Correct 583 ms 10108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1008 ms 11384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1040 ms 9000 KB Time limit exceeded
2 Halted 0 ms 0 KB -