| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1343726 | dex111222333444555 | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++20 | 17 ms | 4328 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) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
