제출 #1282176

#제출 시각아이디문제언어결과실행 시간메모리
1282176KickingKunGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
0 / 100
5 ms572 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define ld long double #define bigint __int128 #define emb emplace_back #define pb push_back #define pii pair <int, int> #define fi first #define se second #define all(v) v.begin(), v.end() #define Task "" #define MASK(k) (1ull << k) #define bitcnt(k) __builtin_popcount(k) #define testBit(n, k) ((n >> k) & 1) #define flipBit(n, k) (n ^ (1ll << k)) #define offBit(n, k) (n & ~MASK(k)) #define onBit(n, k) (n | (1ll << k)) template <class T> bool minimize(T &a, T b) {if (a > b) {a = b; return true;} return false;} template <class T> bool maximize(T &a, T b) {if (a < b) {a = b; return true;} return false;} const int N = 2e5 + 5, lim = 60, mod = 1e9 + 7; const ll INF = 1e18; int n, a[N]; namespace sub2 { int le[2001], ri[2001]; void solve() { le[1] = 1; ri[n] = n; for (int i = 2; i <= n; i++) le[i] = (a[i - 1] < a[i] ? le[i - 1] : i); for (int i = n - 1; i > 0; i--) ri[i] = (a[i + 1] < a[i] ? ri[i + 1] : i); ll res = INF; for (int i = 1; i <= n; i++) { ll ans = 0; for (int l = le[i], r = ri[i]; l > 1 || r < n;) { if (l == 1) ans += max(0, a[r + 1] + 1 - a[r]), r = ri[r + 1]; else if (r == n) ans += max(0, a[l - 1] + 1 - a[l]), l = le[l - 1]; else { ans += max({0, a[r + 1] + 1 - a[r], a[l - 1] + 1 - a[l]}); l = le[l - 1]; r = ri[r + 1]; } } minimize(res, ans); } cout << res; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 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]; sub2::solve(); }

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

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