#include <iostream> #include <vector> #include <queue> #include <map> #include <algorithm> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; map<int, int> m; vector<int> znaczki_od_k(n + 1); znaczki_od_k[1] = n; for (int i =0; i < n; i++) { int a; cin >> a; m[a]++; } auto pr = max_element( begin(m), end(m), [] (const pair<int, int> & p1, const pair<int, int> & p2) { return p1.second < p2.second; } ); for (int k = 2; k <= n; k++) { if (k > pr->second) { znaczki_od_k[k] = 0; continue; } int sum = 0; for (auto key : m) { sum += key.second / k; } znaczki_od_k[k] = sum * k; } for (int i = 1; i <= n; i++) { cout << znaczki_od_k[i] << " "; } cout << "\n"; }
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 | #include <iostream> #include <vector> #include <queue> #include <map> #include <algorithm> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; map<int, int> m; vector<int> znaczki_od_k(n + 1); znaczki_od_k[1] = n; for (int i =0; i < n; i++) { int a; cin >> a; m[a]++; } auto pr = max_element( begin(m), end(m), [] (const pair<int, int> & p1, const pair<int, int> & p2) { return p1.second < p2.second; } ); for (int k = 2; k <= n; k++) { if (k > pr->second) { znaczki_od_k[k] = 0; continue; } int sum = 0; for (auto key : m) { sum += key.second / k; } znaczki_od_k[k] = sum * k; } for (int i = 1; i <= n; i++) { cout << znaczki_od_k[i] << " "; } cout << "\n"; } |