#include <iostream> #include <string> #include <bitset> #include <utility> #include <vector> #include <array> #include <map> #include <algorithm> #include <deque> #include <unordered_set> #include <unordered_map> #include <memory> using Counter = std::unordered_map<int, int>; int solve_one(int i, Counter const& counter) { int count = 0; for (auto const& [_, value] : counter) { // std::cout << (value/i) << std::endl; count += i * (value/i); } return count; } void solve(int n, Counter const& counter) { std::vector<int> result(n, 0); for (auto const& [_, value] : counter) { for (int i = 1; i<=value; ++i) { result[i-1] += i * (value/i); } } std::cout << result.at(0); for (int i = 1; i < n; i++) { std::cout << " " << result.at(i); } std::cout << std::endl; } int main() { int n; std::cin >> n; Counter counter; for (int i = 0; i<n; ++i) { int tmp; std::cin >> tmp; counter[tmp]++; } solve(n, counter); 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #include <iostream> #include <string> #include <bitset> #include <utility> #include <vector> #include <array> #include <map> #include <algorithm> #include <deque> #include <unordered_set> #include <unordered_map> #include <memory> using Counter = std::unordered_map<int, int>; int solve_one(int i, Counter const& counter) { int count = 0; for (auto const& [_, value] : counter) { // std::cout << (value/i) << std::endl; count += i * (value/i); } return count; } void solve(int n, Counter const& counter) { std::vector<int> result(n, 0); for (auto const& [_, value] : counter) { for (int i = 1; i<=value; ++i) { result[i-1] += i * (value/i); } } std::cout << result.at(0); for (int i = 1; i < n; i++) { std::cout << " " << result.at(i); } std::cout << std::endl; } int main() { int n; std::cin >> n; Counter counter; for (int i = 0; i<n; ++i) { int tmp; std::cin >> tmp; counter[tmp]++; } solve(n, counter); return 0; } |