Submission #378310

# Submission time Handle Problem Language Result Execution time Memory
378310 2021-03-16T12:53:47 Z smjleo Growing Vegetables is Fun 4 (JOI21_ho_t1) C++14
100 / 100
28 ms 5740 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define int long long
#define nl '\n'
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
mt19937 rng((unsigned)chrono::steady_clock::now().time_since_epoch().count());
const int mod = 1000000007, mod2 = 998244353;

// change this
const int N = 200005;

int n, arr[N], pf[N], sf[N], ans = 1e18;

signed main() {
    io;
    cin >> n;
    for (int i=0; i<n; i++) cin >> arr[i];
    for (int i=1; i<n; i++) {
        // calculate prefix
        pf[i] = pf[i-1];
        if (arr[i-1] < arr[i]) continue;
        pf[i] += arr[i-1] - arr[i] + 1;
    }   // pf[i]: number of operations to make 1...i strictly increasing
    for (int i=n-2; i>=0; i--) {
        // calculate suffix
        sf[i] = sf[i+1];
        if (arr[i] > arr[i+1]) continue;
        sf[i] += arr[i+1] - arr[i] + 1;
    }   // sf[i]: number of operations to make i...n strictly decreasing

    for (int i=0; i<n; i++) {
        ans = min(ans, max(pf[i], sf[i]));
    }

    cout << ans << nl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 28 ms 5740 KB Output is correct
27 Correct 27 ms 4972 KB Output is correct
28 Correct 27 ms 5100 KB Output is correct
29 Correct 27 ms 4980 KB Output is correct
30 Correct 26 ms 4972 KB Output is correct
31 Correct 27 ms 4972 KB Output is correct
32 Correct 26 ms 4972 KB Output is correct
33 Correct 27 ms 4972 KB Output is correct
34 Correct 27 ms 4972 KB Output is correct
35 Correct 22 ms 4972 KB Output is correct
36 Correct 23 ms 4972 KB Output is correct
37 Correct 24 ms 4972 KB Output is correct
38 Correct 27 ms 4972 KB Output is correct
39 Correct 26 ms 4972 KB Output is correct
40 Correct 28 ms 5100 KB Output is correct
41 Correct 26 ms 4972 KB Output is correct
42 Correct 26 ms 4972 KB Output is correct
43 Correct 26 ms 4972 KB Output is correct
44 Correct 26 ms 4972 KB Output is correct
45 Correct 26 ms 5092 KB Output is correct
46 Correct 26 ms 4972 KB Output is correct
47 Correct 27 ms 5100 KB Output is correct
48 Correct 26 ms 4972 KB Output is correct