Submission #248790

#TimeUsernameProblemLanguageResultExecution timeMemory
248790SortingToys (CEOI18_toy)C++14
100 / 100
4148 ms86696 KiB
#include <bits/stdc++.h> using namespace std; unordered_map<int, set<int>> dp; void solve(int n){ vector<int> div; for(int i = 2; i * i <= n; ++i){ if(n % i == 0){ div.push_back(i); if(i * i != n) div.push_back(n / i); } } div.push_back(n); for(int d: div){ int nd = n / d; for(int x: dp[n]) dp[nd].insert(x + d - 1); } } int main(){ ios::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<int> div; for(int i = 2; i * i <= n; ++i){ if(n % i == 0){ div.push_back(i); if(i * i != n) div.push_back(n / i); } } div.push_back(n); sort(div.begin(), div.end()); reverse(div.begin(), div.end()); dp[n].insert(0); for(int d: div) solve(d); cout << dp[1].size() << "\n"; for(int x: dp[1]) cout << x << " "; cout << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...