#include <ios> #include <functional> #include <cassert> #include <vector> #define REP(i, n) for(int i=0; i<(n); ++i) #define SREP(n) REP(_ ## n, n) #define FOR(i, p, n) for(int i=(p); i<=(n); ++i) #define RFOR(i, p, n) for(int i=(p); i>=(n); --i) #define pb push_back #define eb emplace_back #define C const #define V std::vector #define F std::function #define R std::ranges #define RV std::ranges::views #define sz(A) int(A.size()) #define all(A) A.begin(), A.end() #define rall(A) A.rbegin(), A.rend() typedef long long ll; typedef long double ld; typedef V <int> vi; typedef V <vi> vvi; typedef V <bool> vb; typedef V <char> vc; typedef V <ll> vll; typedef const int ci; typedef const ll cll; int I(){ int z; scanf("%d", &z); return z; } int main(){ ci n=I(); vi kub(n); SREP(n) ++kub[I()-1]; std::sort(rall(kub)); while (!kub.back()) kub.pop_back(); int w=0; REP(p, sz(kub)){ ++w; for (--kub[p]; p+1<sz(kub)&&kub[p]; --kub[p]) if (!--kub.back()) kub.pop_back(); } printf("%d\n", w); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #include <ios> #include <functional> #include <cassert> #include <vector> #define REP(i, n) for(int i=0; i<(n); ++i) #define SREP(n) REP(_ ## n, n) #define FOR(i, p, n) for(int i=(p); i<=(n); ++i) #define RFOR(i, p, n) for(int i=(p); i>=(n); --i) #define pb push_back #define eb emplace_back #define C const #define V std::vector #define F std::function #define R std::ranges #define RV std::ranges::views #define sz(A) int(A.size()) #define all(A) A.begin(), A.end() #define rall(A) A.rbegin(), A.rend() typedef long long ll; typedef long double ld; typedef V <int> vi; typedef V <vi> vvi; typedef V <bool> vb; typedef V <char> vc; typedef V <ll> vll; typedef const int ci; typedef const ll cll; int I(){ int z; scanf("%d", &z); return z; } int main(){ ci n=I(); vi kub(n); SREP(n) ++kub[I()-1]; std::sort(rall(kub)); while (!kub.back()) kub.pop_back(); int w=0; REP(p, sz(kub)){ ++w; for (--kub[p]; p+1<sz(kub)&&kub[p]; --kub[p]) if (!--kub.back()) kub.pop_back(); } printf("%d\n", w); } |