Submission #1018431

# Submission time Handle Problem Language Result Execution time Memory
1018431 2024-07-10T04:01:30 Z caterpillow Baloni (COCI15_baloni) C++17
100 / 100
583 ms 95972 KB
#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

baloni.cpp:58:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   58 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 47448 KB Output is correct
2 Correct 11 ms 47360 KB Output is correct
3 Correct 11 ms 47448 KB Output is correct
4 Correct 12 ms 47448 KB Output is correct
5 Correct 487 ms 91088 KB Output is correct
6 Correct 583 ms 95972 KB Output is correct
7 Correct 482 ms 87428 KB Output is correct
8 Correct 441 ms 86868 KB Output is correct
9 Correct 497 ms 89384 KB Output is correct
10 Correct 520 ms 90708 KB Output is correct