Submission #1256800

#TimeUsernameProblemLanguageResultExecution timeMemory
1256800son2008Growing Vegetables is Fun 4 (JOI21_ho_t1)C++20
0 / 100
0 ms328 KiB
#include <bits/stdc++.h>
using namespace std;
#define ii pair<int, int>
#define fi first
#define se second
// #define int long long
#define ll long long
#define ld double
#define mp make_pair
#define lg2 30
#define iii pair<int, ii>
#define iiii pair<ii, ii>
#define base 29
#define eps 1e-8
#define MASK(i) (1LL << (i))
#define BIT(S, i) (((S) >> (i)) & 1)
int dx[] = {0LL, 0LL, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0LL, 0LL, 1, -1, 1, -1};
const int maxn = 4e5 + 5;
const int mod = 1e9 + 7;
int n, a[maxn], pre[maxn], suf[maxn];
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#define task "task"
    if (fopen(task ".inp", "r"))
    {
        freopen(task ".inp", "r", stdin);
        freopen(task ".out", "w", stdout);
    }
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    for (int i = 2; i <= n; i++)
    {
        pre[i] = pre[i - 1] + max(0, a[i - 1] - a[i] + 1);
    }
    for (int i = n - 1; i >= 1; i--)
    {
        suf[i] = suf[i + 1] + max(0, a[i + 1] - a[i] + 1);
    }
    int ans = 1e9;
    for (int i = 1; i <= n; i++)
    {
        ans = min(ans, max(pre[i], suf[i]));
    }
    cout << ans;
    cerr << endl
         << "TIME : " << clock() * 0.001 << "s" << endl;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         freopen(task ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:31:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         freopen(task ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...