Submission #1006978

# Submission time Handle Problem Language Result Execution time Memory
1006978 2024-06-24T10:29:42 Z faqinyeager Growing Vegetables is Fun 4 (JOI21_ho_t1) C++17
100 / 100
57 ms 7252 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
using ll = long long;
 
int n;
vector<ll> a, pref, suff;
 
int main(){
    cin >> n;
    
    a.resize(n);
    pref.resize(n, 0);
    suff.resize(n, 0);
    
    for(int i = 0; i < n; i++) cin >> a[i];
    
    for(int i = 1; i < n; i++) if(a[i - 1] >= a[i]) pref[i] = a[i - 1] - a[i] + 1;
    for(int i = n - 2; i >= 0; i--) if(a[i] <= a[i + 1]) suff[i] = a[i + 1] - a[i] + 1;
    
    for(int i = 1; i < n; i++) pref[i] += pref[i - 1];
    for(int i = n - 2; i >= 0; i--) suff[i] += suff[i + 1];
    
    if(pref[n - 1] == 0 || suff[0] == 0){
        cout << 0; return 0;
    }
    
    ll ans = 1e14;
    
    for(int i = 0; i < n; i++){
        ans = min(ans, max(pref[i], suff[i]));
    }
    
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 448 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 448 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 49 ms 6908 KB Output is correct
27 Correct 49 ms 7028 KB Output is correct
28 Correct 48 ms 6996 KB Output is correct
29 Correct 53 ms 7024 KB Output is correct
30 Correct 39 ms 6232 KB Output is correct
31 Correct 49 ms 6996 KB Output is correct
32 Correct 48 ms 7004 KB Output is correct
33 Correct 48 ms 6912 KB Output is correct
34 Correct 56 ms 7036 KB Output is correct
35 Correct 32 ms 6144 KB Output is correct
36 Correct 34 ms 6228 KB Output is correct
37 Correct 36 ms 6140 KB Output is correct
38 Correct 48 ms 6908 KB Output is correct
39 Correct 57 ms 7252 KB Output is correct
40 Correct 49 ms 6996 KB Output is correct
41 Correct 47 ms 7000 KB Output is correct
42 Correct 44 ms 6788 KB Output is correct
43 Correct 49 ms 6908 KB Output is correct
44 Correct 47 ms 6996 KB Output is correct
45 Correct 50 ms 6940 KB Output is correct
46 Correct 48 ms 6996 KB Output is correct
47 Correct 48 ms 7004 KB Output is correct
48 Correct 48 ms 6996 KB Output is correct