Submission #254733

# Submission time Handle Problem Language Result Execution time Memory
254733 2020-07-30T13:50:10 Z alrad Baloni (COCI15_baloni) C++17
100 / 100
1008 ms 92536 KB
#include <bits/stdc++.h>

using namespace std;

/*
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

template <class T> inline T gcd(T a , T b) { return !a ? b : gcd(b % a , a); }
template <class T> inline T lcm(T a , T b) {return (a * b) / gcd(a , b) ; }

#define all(x) x.begin(), x.end()
#define debug(x) { cerr << #x << " = " << x << endl; }

const int MAX = 1e6 + 1;

set<int> bal[MAX];

int main() {
   ios_base :: sync_with_stdio(0);
   cin.tie(0) , cout.tie(0);
   int n;
   cin >> n;
   for (int i = 0; i < n; i++) {
      int h;
      cin >> h;
      bal[h].insert(i);
   }
   int ans = 0;
   for (int h = MAX - 1; h >= 0; h--) {
      while (!bal[h].empty()) {
         ans++;
         int cur = *bal[h].begin();
         bal[h].erase(bal[h].begin());
         for (int hlow = h - 1; hlow >= 0; hlow--) {
            auto kill = bal[hlow].lower_bound(cur);
            if (kill == bal[hlow].end()) {
               break;
            }
            cur = *kill;
            bal[hlow].erase(kill);
         }
      }
   }
   cout << ans << '\n';
   return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 35 ms 47488 KB Output is correct
2 Correct 35 ms 47360 KB Output is correct
3 Correct 32 ms 47488 KB Output is correct
4 Correct 33 ms 47488 KB Output is correct
5 Correct 902 ms 88124 KB Output is correct
6 Correct 1008 ms 92536 KB Output is correct
7 Correct 801 ms 84552 KB Output is correct
8 Correct 805 ms 84232 KB Output is correct
9 Correct 811 ms 86392 KB Output is correct
10 Correct 905 ms 87852 KB Output is correct