Submission #248788

#TimeUsernameProblemLanguageResultExecution timeMemory
248788SortingToys (CEOI18_toy)C++14
79 / 100
5076 ms9632 KiB
#include <bits/stdc++.h> using namespace std; unordered_map<int, vector<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){ vector<int> add; for(int x: dp[n]) add.push_back(x + d - 1); int i = 0, j = 0; int nd = n / d; vector<int> new_v; while(i != add.size() && j != dp[nd].size()){ if(add[i] == dp[nd][j]) new_v.push_back(add[i]), i++, j++; else if(add[i] < dp[nd][j]) new_v.push_back(add[i]), i++; else new_v.push_back(dp[nd][j]), j++; } while(i != add.size()) new_v.push_back(add[i]), i++; while(j != dp[nd].size()) new_v.push_back(dp[nd][j]), j++; dp[nd] = new_v; } } 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].push_back(0); for(int d: div) solve(d); cout << dp[1].size() << "\n"; for(int x: dp[1]) cout << x << " "; cout << "\n"; }

Compilation message (stderr)

toy.cpp: In function 'void solve(int)':
toy.cpp:26:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(i != add.size() && j != dp[nd].size()){
               ~~^~~~~~~~~~~~~
toy.cpp:26:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(i != add.size() && j != dp[nd].size()){
                                  ~~^~~~~~~~~~~~~~~~
toy.cpp:35:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(i != add.size())
               ~~^~~~~~~~~~~~~
toy.cpp:37:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(j != dp[nd].size())
               ~~^~~~~~~~~~~~~~~~
#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...