Submission #783699

#TimeUsernameProblemLanguageResultExecution timeMemory
783699CookieGlobal Warming (NOI13_gw)C++14
40 / 40
195 ms21508 KiB
#include<bits/stdc++.h> #include<fstream> using namespace std; ifstream fin("FEEDING.INP"); ofstream fout("FEEDING.OUT"); #define sz(a) (int)a.size() #define ll long long #define pb push_back #define forr(i, a, b) for(int i = a; i < b; i++) #define dorr(i, a, b) for(int i = a; i >= b; i--) #define ld long double #define vt vector #include<fstream> #define fi first #define se second #define pll pair<ll, ll> #define pii pair<int, int> const ld PI = 3.14159265359; using u128 = __uint128_t; const int x[4] = {1, -1, 0, 0}; const int y[4] = {0, 0, 1, -1}; const ll mod = 1e9 + 7, inf = 1e16; const int mxn = 1e6 + 5; int cnt = 0; int n; int h[mxn + 1]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; vt<pii>comp; forr(i, 0, n){ cin >> h[i]; comp.pb({h[i], i}); } sort(comp.begin(), comp.end()); vt<bool>ok(n + 1); int ans = 0; for(int i = 0; i < sz(comp);){ int r = i + 1; while(r < sz(comp) && comp[r].fi == comp[i].fi)r++; for(int j = i; j < r; j++){ int id = comp[j].second; cnt++; if(id && ok[id - 1])cnt--; if(id < n && ok[id + 1])cnt--; ok[id] = 1; } int val = cnt + 1; if(ok[0])val--; if(ok[n - 1])val--; ans = max(ans, val); i = r; } cout << ans; return(0); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...