Submission #991611

#TimeUsernameProblemLanguageResultExecution timeMemory
991611rsinventorGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector <ll> vll; typedef vector<bool> vb; typedef vector <string> vs; typedef vector<char> vc; typedef pair<int, int> pii; typedef vector <pii> vpii; #define all(a) (a).begin(), (a).end() #define pb push_back #define endl "\n" int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); for(int i = 0; i < n; i++) { cin >> a[i]; } vector<int> up(n); vector<int> down(n); for(int i = 1; i < n; i++) { if(a[i]>a[i-1] + up[i-1]) { up[i] = 0; continue; } up[i] = a[i-1] + up[i-1] + 1 - a[i]; } for(int i = n-2; i >= 0; i--) { if(a[i]>a[i+1]+down[i+1]) { down[i] = 0; continue; } down[i] = a[i+1] + down[i+1] + 1 - a[i]; } vector<int> p_up(n+1); vector<int> p_down(n+1); for(int i = 0; i <= n; i++) { p_up[i+1] = up[i] + p_up[i]; p_down[i+1] = down[i] + p_down[i]; } int min_i = 0; int min = p_down[n-1]-p_down[1]; for(int i = 1; i < n; i++) { int sum = p_up[i+1] + p_down[n-1] - p_down[i+1]; // if(i+1<n && a[i]==a[i+1]) { // continue; // } if(sum<min) { min = sum; min_i = i; } } vector<int> to_add; pii middle = {-1, -1}; bool flag = true; for(int i = 0; i < n; i++) { if(i<=min_i) { to_add.pb(up[i]); if (up[i] != 0) { middle.first = i; } } else { to_add.pb(down[i]); if(down[i] != 0 && flag) { middle.second = i; flag = false; } } } if(middle.second==-1 || middle.first==-1) { middle.first=-1; middle.second=-1; } vector<int> curr; int res = 0; flag = false; for(int i = 0; i < n; i++) { if(middle.first==i) { flag = true; } if(middle.second==i) { flag = false; } if(to_add[i]==0 && !flag) { if(curr.size()==0) { continue; } sort(all(curr)); res += curr[curr.size()-1]; curr.clear(); } else { curr.pb(to_add[i]); } } for(int i = 1; i < a.size(); i++) { if(to_add[i]+a[i]==to_add[i-1]+a[i-1]) { res++; to_add[i]++; } } cout << res << endl; return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:108:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |     for(int i = 1; i < a.size(); i++) {
      |                    ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...