Submission #1215243

#TimeUsernameProblemLanguageResultExecution timeMemory
1215243sunflowerGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
6 ms328 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define MASK(x) (1LL << (x)) #define BIT(x, i) (((x) >> (i)) & 1) #define SZ(x) ((int) (x).size()) #define ALL(a) (a).begin(), (a).end() #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i) #define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i) #define debug(x) cout << "[" << #x << " = " << (x) << "]" << endl #define left __left #define right __right #define prev __prev #define next __next #define fi first #define se second template <class X, class Y> bool maximize(X &x, Y y) { if (x < y) return x = y, true; else return false; } template <class X, class Y> bool minimize(X &x, Y y) { if (x > y) return x = y, true; else return false; } int main() { ios_base::sync_with_stdio(false);cin.tie(nullptr); #define task "test" if (fopen(task".inp","r")) { freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } int n; cin >> n; vector <int> a(n), b(n); for (int &x : a) cin >> x; REP(i, n - 1) b[i] = a[i + 1] - a[i]; // peak = K; /** 1.. K - 1 (b[i] >= 1) K ... n - 1 (b[i] <= -1); **/ // FOR(i, 0, cout << x << " "; ll ans = 1e18; FOR(peak, 0, n - 2) { ll prefix = 0; FOR(i, 0, peak - 1) if (b[i] < 1) prefix += 1 - b[i]; ll suffix = 0; FOR(i, peak, n - 2) if (b[i] > -1) suffix += b[i] - (-1); minimize(ans, max(prefix, suffix)); } cout << ans; return 0; } /* Discipline - Calm */

Compilation message (stderr)

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