#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <string> using namespace std; int main() { int n; cin >> n; // vector<int> miasta; vector<int> znaczki; for (int i = 0; i < n; i++) { int x; cin >> x; znaczki.push_back(x); } // sort(znaczki.begin(), znaczki.end()); int last = 0; for (int i = 0; i < n; i++) { int &element = znaczki[i]; if (last == element) { ++miasta[ miasta.size() - 1 ]; } else { last = element; miasta.push_back(1); } } sort(miasta.begin(), miasta.end(), greater<int>()); // vector<int> lasts; int lasuma = 0; bool is = true; for (size_t i = 0; i < miasta.size(); i++) { lasts.push_back(miasta[i]); lasuma += miasta[i]; } int olasuma = lasuma; cout << lasuma; for (int k = 2; k <= n; k++) { if (is) { lasuma = olasuma; for (int i = (lasts.size() - 1); i >= 0; --i) { int nlast = miasta[i]; nlast /= k; nlast *= k; lasuma -= lasts[i] - nlast; //lasts[i] = nlast; if (lasts[i] == 0) { lasts.erase(lasts.begin() + i); --i; } if (lasts.size() == 0) { is = false; break; } } cout << " " << lasuma; } else { 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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | #include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <string> using namespace std; int main() { int n; cin >> n; // vector<int> miasta; vector<int> znaczki; for (int i = 0; i < n; i++) { int x; cin >> x; znaczki.push_back(x); } // sort(znaczki.begin(), znaczki.end()); int last = 0; for (int i = 0; i < n; i++) { int &element = znaczki[i]; if (last == element) { ++miasta[ miasta.size() - 1 ]; } else { last = element; miasta.push_back(1); } } sort(miasta.begin(), miasta.end(), greater<int>()); // vector<int> lasts; int lasuma = 0; bool is = true; for (size_t i = 0; i < miasta.size(); i++) { lasts.push_back(miasta[i]); lasuma += miasta[i]; } int olasuma = lasuma; cout << lasuma; for (int k = 2; k <= n; k++) { if (is) { lasuma = olasuma; for (int i = (lasts.size() - 1); i >= 0; --i) { int nlast = miasta[i]; nlast /= k; nlast *= k; lasuma -= lasts[i] - nlast; //lasts[i] = nlast; if (lasts[i] == 0) { lasts.erase(lasts.begin() + i); --i; } if (lasts.size() == 0) { is = false; break; } } cout << " " << lasuma; } else { cout << " " << 0; } } return 0; } |