제출 #426540

#제출 시각아이디문제언어결과실행 시간메모리
426540HideoGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
1 ms344 KiB
#include <bits/stdc++.h> using namespace std; #define all(s) s.begin(), s.end() #define int long long #define fr first #define sc second #define pb push_back #define mk make_pair const int N = 2e5 + 7; const int INF = 1e9 + 7; int a[N], sf[N], pr[N], m[N]; int n, ans; main (){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++){ cin >> a[i]; } for (int i = n - 1; i >= 1; i--){ sf[i] = sf[i + 1] + max(0ll, a[i + 1] - a[i] + 1); m[i] = max(m[i], a[i + 1] - a[i] + 1); } ans = sf[1]; int mx = 0; for (int i = 2; i < n; i++){ pr[i] = pr[i - 1] + max(0ll, a[i - 1] - a[i] + 1); int f1 = pr[i - 1], f2 = sf[i + 1], tk = 0; if (a[i] + f2 > a[i - 1]){ f1 -= min(mx, min(a[i] + f2 - a[i - 1] - 1, f2)); tk = min(mx, min(a[i] + f2 - a[i - 1] - 1, f2)); } else { f1 += a[i - 1] - a[i] - f2 + 1; } if (a[i] + f1 > a[i + 1]){ f2 -= min(f2 - tk, min(m[i + 1], min(a[i] + f1 - a[i + 1] - 1, f1))); } else { f2 += a[i + 1] - a[i] - f1 + 1; } ans = min(ans, f1 + f2); mx = max(mx, a[i - 1] - a[i] + 1); } pr[n] = pr[n - 1] + max(0ll, a[n - 1] - a[n] + 1); ans = min(ans, pr[n]); cout << ans << endl; }

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

Main.cpp:17:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   17 | main (){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...