Submission #998598

#TimeUsernameProblemLanguageResultExecution timeMemory
998598codefoxToys (CEOI18_toy)C++14
100 / 100
3172 ms16016 KiB
#include <bits/stdc++.h> using namespace std; map<int, vector<int>> opt; map<int, bool> d; vector<int> dfs(int i) { if (d[i]) return opt[i]; d[i] = 1; map<int, bool> m; vector<int> nums; nums.push_back(i-1); m[i-1]= 1; opt[i].push_back(i-1); for (int j = 2; j*j <= i; j++) { if (i%j==0) { for (int ele:dfs(i/j)) { if (!m[ele+j-1]) { nums.push_back(ele+j-1); opt[i].push_back(ele+j-1); } m[ele+j-1]=1; } } } return nums; } int main() { int n; cin >> n; vector<int> v(dfs(n)); sort(v.begin(), v.end()); cout << v.size()<< "\n"; for (int ele:v) cout << ele << " "; return 0; }
#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...