#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
map<int, int> stamps;
map<int, int> multiplicity;
int count, country;
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> count;
vector<int> numShared(count, 0);
for (int i=0; i<count; ++i) {
cin >> country;
++stamps[country];
}
numShared[1] = count;
for (const auto & st : stamps) {
++multiplicity[st.second];
}
for (const auto & entry : multiplicity) {
// cout << "-> " << entry.first << " : " << entry.second << endl;
if (entry.first == 1)
continue;
for (int parts=2; parts <= entry.first / 2; ++parts) {
numShared[parts] += parts * (entry.first / parts) * entry.second;
}
for (int parts=entry.first/2+1; parts<=entry.first; ++parts) {
numShared[parts] += parts * entry.second;
}
}
cout << numShared[1];
for (int i=2; i<=count; ++i)
cout << " " << numShared[i];
cout << endl;
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 | #include <iostream> #include <map> #include <vector> using namespace std; int main() { map<int, int> stamps; map<int, int> multiplicity; int count, country; ios::sync_with_stdio(false); cin.tie(nullptr); cin >> count; vector<int> numShared(count, 0); for (int i=0; i<count; ++i) { cin >> country; ++stamps[country]; } numShared[1] = count; for (const auto & st : stamps) { ++multiplicity[st.second]; } for (const auto & entry : multiplicity) { // cout << "-> " << entry.first << " : " << entry.second << endl; if (entry.first == 1) continue; for (int parts=2; parts <= entry.first / 2; ++parts) { numShared[parts] += parts * (entry.first / parts) * entry.second; } for (int parts=entry.first/2+1; parts<=entry.first; ++parts) { numShared[parts] += parts * entry.second; } } cout << numShared[1]; for (int i=2; i<=count; ++i) cout << " " << numShared[i]; cout << endl; return 0; } |
English