#include <algorithm> #include <cstdio> #include <unordered_map> #include <vector> const bool DEBUG = true; int main() { int c, N; std::unordered_map<int, int> map; std::vector<int> uses; scanf("%d", &N); for (int i = 0; i < N; ++i) { scanf("%d", &c); if (map.contains(c)) { map[c] += 1; } else { map[c] = 1; } } for (const std::pair<const int, int> &pair : map) { uses.push_back(pair.second); } sort(uses.begin(), uses.end(), std::greater<int>()); // if (DEBUG) { // for (const int &u : uses) { // printf("%d ", u); // } // puts(""); // } printf("%d ", N); for (int div = 2; div<=N; ++div) { int total = 0; for (auto it = uses.begin(); it != uses.end() && *it >= div; ++it){ total += *it - (*it % div); } printf("%d ", total); } puts(""); 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 46 47 | #include <algorithm> #include <cstdio> #include <unordered_map> #include <vector> const bool DEBUG = true; int main() { int c, N; std::unordered_map<int, int> map; std::vector<int> uses; scanf("%d", &N); for (int i = 0; i < N; ++i) { scanf("%d", &c); if (map.contains(c)) { map[c] += 1; } else { map[c] = 1; } } for (const std::pair<const int, int> &pair : map) { uses.push_back(pair.second); } sort(uses.begin(), uses.end(), std::greater<int>()); // if (DEBUG) { // for (const int &u : uses) { // printf("%d ", u); // } // puts(""); // } printf("%d ", N); for (int div = 2; div<=N; ++div) { int total = 0; for (auto it = uses.begin(); it != uses.end() && *it >= div; ++it){ total += *it - (*it % div); } printf("%d ", total); } puts(""); return 0; } |