# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
134451 | dragonslayerit | Toys (CEOI18_toy) | C++14 | 3163 ms | 86728 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <vector>
#include <map>
#include <set>
std::vector<int> factors;
std::map<int,std::set<int> > memo;
const std::set<int>& dfs(int n){
if(memo.count(n)) return memo[n];
auto& ans=memo[n];
if(n==1){
ans.insert(0);
}else{
for(int f:factors){
if(n%f==0){
auto& set=dfs(n/f);
for(int x:set){
ans.insert(x+(f-1));
}
}
}
}
return ans;
}
int main(){
int N;
scanf("%d",&N);
for(int x=1;x*x<=N;x++){
if(N%x==0){
factors.push_back(x);
if(x*x<N){
factors.push_back(N/x);
}
}
}
auto& ans=dfs(N);
printf("%d\n",(int)ans.size());
for(int x:ans){
printf("%d ",x);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |