Submission #1055144

# Submission time Handle Problem Language Result Execution time Memory
1055144 2024-08-12T14:53:28 Z manhlinh1501 Growing Vegetables is Fun 4 (JOI21_ho_t1) C++17
0 / 100
1 ms 4444 KB
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const i64 oo64 = 1e18;
using pll = pair<i64, i64>;
const int MAXN = 2e5 + 5;

int N;
i64 a[MAXN];
i64 b[MAXN];
pll prefix[MAXN];
bool is_dec[MAXN];

void PREFIX(i64 a[]) {
    i64 c = 0;
    for(int i = 1; i <= N; i++) {
        prefix[i].second = prefix[i - 1].second;
        a[i] += c;
        if(a[i] <= prefix[i - 1].first) {
            i64 x = (prefix[i - 1].first + 1) - a[i];
            c += x;
            prefix[i].second += x;
            a[i] = prefix[i - 1].first + 1;
        }
        prefix[i].first = max(prefix[i - 1].first + 1, a[i]);
    }
}

signed main() {
#define TASK "code"

    if (fopen(TASK ".inp", "r")) {
        freopen(TASK ".inp", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> N;
    for(int i = 1; i <= N; i++) cin >> a[i];
    for(int i = 1; i <= N; i++) b[i] = a[i];
    PREFIX(b);
    for(int i = N; i >= 1; i--) {
        if(a[i] > a[i + 1]) is_dec[i] = true;
        else break;
    }
    i64 ans = oo64;
    for(int i = 0; i <= N; i++) {
        if(is_dec[i]) ans = min(ans, prefix[i].second);
    }
    cout << ans;
    return (0 ^ 0);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         freopen(TASK ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         freopen(TASK ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Incorrect 0 ms 4444 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Incorrect 0 ms 4444 KB Output isn't correct
4 Halted 0 ms 0 KB -