Submission #679951

#TimeUsernameProblemLanguageResultExecution timeMemory
679951redstonegamer22Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
0 ms212 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main() { int n; cin >> n; vector<int> a(n); for(auto &e : a) cin >> e; int watered = 0; int l = 1, r = n - 2; while(l < r) { // cerr << l << " " << r << " " << watered << endl; while(l <= r && a[l] + watered > a[l - 1]) { a[l] += watered; l += 1; } while(r >= l && a[r] + watered > a[r + 1]) { a[r] += watered; r -= 1; } // cerr << l << " " << r << " " << watered << endl; if(r < l) break; // cerr << a[l - 1] << " " << a[l] << " " << a[r + 1] << " " << a[r] << endl; int next = min(a[l - 1] - (a[l] + watered) + 1, a[r + 1] - (a[r] + watered) + 1); watered += next; } bool ok = false; for(int i = 0; i + 1 < a.size(); i++) if(a[i] == a[i + 1]) ok |= 1; // for(auto e : a) cerr << e << " "; cerr << endl; cout << watered + (int)ok << endl; }

Compilation message (stderr)

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