제출 #1343726

#제출 시각아이디문제언어결과실행 시간메모리
1343726dex111222333444555Growing Vegetables is Fun 4 (JOI21_ho_t1)C++20
100 / 100
17 ms4328 KiB
#include <bits/stdc++.h>
#define ii pair<int, int>
#define fi first
#define se second
#define siz(v) ((int)(v).size())
#define all(v) begin((v)), end(v)
#define BIT(x, i) (((x) >> (i)) & 1)
#define MASK(i) (1LL << (i))
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
#define dbg(x) "[" #x " = " << x << "]"
#define lli pair<long long, int>
#define left __left
#define right __right

using namespace std;

const int MAXN = 2e5 + 5, MAXK = 16, LOG = 20, infINT = 1e9 + 23737;
const long long inf = 1e18 + 5;

const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};

template<class X, class Y> bool minimize(X &x, const Y &y){return x > y ? x = y, 1: 0;}
template<class X, class Y> bool maximize(X &x, const Y &y){return x < y ? x = y, 1: 0;}

int numVal, h[MAXN];
long long f[MAXN], g[MAXN];

void input(){
    cin >> numVal;
    for(int i = 1; i <= numVal; i++) cin >> h[i];
}

void solve(){
    long long res = inf;
    for(int i = 1; i <= numVal; i++) f[i] = f[i - 1] + max(0, h[i - 1] + 1 - h[i]);
    for(int i = numVal; i >= 1; i--) g[i] = g[i + 1] + max(0, h[i + 1] + 1 - h[i]);
    for(int i = 1; i <= numVal; i++) minimize(res, max(f[i], g[i]));
    cout << res << '\n';
}

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define task "test"
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int t = 1;
    // cin >> t;
    while(t--){
        input();
        solve();
    }
    cerr << TIME << ".s\n";
}

컴파일 시 표준 에러 (stderr) 메시지

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