Submission #1018431

#TimeUsernameProblemLanguageResultExecution timeMemory
1018431caterpillowBaloni (COCI15_baloni)C++17
100 / 100
583 ms95972 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pl = pair<ll, ll>; using pi = pair<int, int>; #define vt vector #define f first #define s second #define pb push_back #define all(x) x.begin(), x.end() #define size(x) ((int) (x).size()) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--) #define F0R(i, b) FOR (i, 0, b) #define endl '\n' const ll INF = 1e18; const int inf = 1e9; template<template<typename> class Container, typename T> ostream& operator<<(ostream& os, Container<T> o) { os << "{"; int g = size(o); for (auto i : o) os << i << ((--g) == 0 ? "" : ", "); os << "}"; return os; } void _print() { cerr << "\n"; } template<typename T, typename ...V> void _print(T t, V... v) { cerr << t; if (sizeof...(v)) cerr << ", "; _print(v...); } #ifdef LOCAL #define dbg(x...) cerr << #x << " = "; _print(x); #else #define dbg(x...) #define cerr if (0) std::cerr #endif /* greedy? idk ill just try to see if it works */ const int maxn = 1e6; int n, ans; int a[maxn]; set<int> pool[maxn]; main() { cin.tie(0)->sync_with_stdio(0); cin >> n; F0R (i, n) cin >> a[i]; F0R (i, n) pool[a[i]].insert(i); F0R (i, n) { if (pool[a[i]].count(i)) { ans++; int h = a[i]; int pos = 0; while (h >= 0) { auto it = pool[h].lower_bound(pos); if (it == pool[h].end()) break; pos = *it; pool[h].erase(it); h--; } } } cout << ans << endl; }

Compilation message (stderr)

baloni.cpp:58:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   58 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...