제출 #1055144

#제출 시각아이디문제언어결과실행 시간메모리
1055144manhlinh1501Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
1 ms4444 KiB
#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); }

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

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...