#include <bits/stdc++.h> using namespace std; int main (){ ios::sync_with_stdio(0); cin.tie(0); int n, c, j{}, tmp{}, koniec; cin >> n; vector <int> L(n), Ll; for (auto &i : L) cin >> i; sort (L.begin(), L.end()); c = L[0]; //for (auto zz : L) //cout << zz << ' '; //cout << endl; for (auto i : L) if (i == c) ++j; else { Ll.push_back(j); j = 1; c = i; } Ll.push_back(j); sort (Ll.begin(), Ll.end()); koniec = Ll.size() - 1; cout << n << ' '; for (auto zz : Ll) tmp += zz & 1; cout << n - tmp << ' '; for (j = 3; j <= n; ++j) { if (j > Ll[koniec]) break; tmp = 0; for (int z = koniec; z >= 0 and Ll[z] >= j; --z) tmp += Ll[z]/j; cout << tmp * j << ' '; } for (; j <= n; ++j) cout << "0 "; return 0; }
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 | #include <bits/stdc++.h> using namespace std; int main (){ ios::sync_with_stdio(0); cin.tie(0); int n, c, j{}, tmp{}, koniec; cin >> n; vector <int> L(n), Ll; for (auto &i : L) cin >> i; sort (L.begin(), L.end()); c = L[0]; //for (auto zz : L) //cout << zz << ' '; //cout << endl; for (auto i : L) if (i == c) ++j; else { Ll.push_back(j); j = 1; c = i; } Ll.push_back(j); sort (Ll.begin(), Ll.end()); koniec = Ll.size() - 1; cout << n << ' '; for (auto zz : Ll) tmp += zz & 1; cout << n - tmp << ' '; for (j = 3; j <= n; ++j) { if (j > Ll[koniec]) break; tmp = 0; for (int z = koniec; z >= 0 and Ll[z] >= j; --z) tmp += Ll[z]/j; cout << tmp * j << ' '; } for (; j <= n; ++j) cout << "0 "; return 0; } |