제출 #1010450

#제출 시각아이디문제언어결과실행 시간메모리
1010450HishamAlshehriGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
1 ms4696 KiB
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> using namespace std; //using namespace __gnu_pbds; #define int long long #define mod 1000000007 #define base 7001 #define base2 757 // #define pi acos(-1) #define double long double //#define ordered_set tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> //#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> #pragma GCC optimize("O3,Ofast,unroll-loops") #pragma GCC target("avx2,sse3,sse4,avx") constexpr int maxn = 1000001; const int N = 1 << (int)(ceil(log2(maxn))); int n, a[maxn], b[maxn]; int prf[maxn][3], suf[maxn][3]; signed main() { cin.tie(0) -> sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = n; i >= 1; i--) { b[i] = a[i]; suf[i][0] = suf[i + 1][0]; suf[i][2] = max((a[i + 1] + 1 - a[i]) - suf[i + 1][2], 0ll); suf[i][0] += suf[i][2]; suf[i][1] = a[i] + max(a[i + 1] + 1 - a[i], 0ll); a[i] += max(a[i + 1] + 1 - a[i], 0ll); } for (int i = 1; i <= n; i++) { a[i] = b[i]; prf[i][0] = prf[i - 1][0]; prf[i][2] = max((a[i - 1] + 1 - a[i]) - prf[i - 1][2], 0ll); prf[i][0] += prf[i][2]; prf[i][1] = a[i] + max(a[i - 1] + 1 - a[i], 0ll); a[i] += max(a[i - 1] + 1 - a[i], 0ll); } int mn = INT_MAX; // for(int i = 0; i < n; i++) // { // cout << suf[i + 1][0] << " " << prf[i + 1][0] << "\n"; // } // cout << "\n"; for (int i = 1; i <= n; i++) { int idx = i, jdx = i; if (suf[i][1] > prf[i][1]) idx--; else jdx++; //cout << suf[jdx][0] << " " << prf[idx][0] << '\n'; mn = min(mn, max(suf[jdx][0], prf[idx][0])); } cout << mn; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...