Submission #161392

#TimeUsernameProblemLanguageResultExecution timeMemory
161392rama_pangToys (CEOI18_toy)C++14
100 / 100
4345 ms86752 KiB
#include <bits/stdc++.h> using namespace std; vector<int> factors; map<int, set<int>> memo; set<int> &solve(int n) { if (memo.count(n)) return memo[n]; auto &ans = memo[n]; if (n == 1) { ans.emplace(0); } else { for (auto &i : factors) { if (n % i) continue; auto &nxt = solve(n / i); for (auto &j : nxt) ans.emplace(j + i - 1); } } return ans; } int main() { int N; scanf("%d", &N); for (int i = 1; i * i <= N; i++) if (N % i == 0) factors.push_back(i), factors.push_back(N / i); sort(factors.begin(), factors.end()); factors.resize(unique(factors.begin(), factors.end()) - factors.begin()); factors.erase(factors.begin()); set<int> &ans = solve(N); printf("%d\n", (int)ans.size()); for (auto i : ans) printf("%d ", i); printf("\n"); }

Compilation message (stderr)

toy.cpp: In function 'int main()':
toy.cpp:24:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int N; scanf("%d", &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...