Submission #490993

#TimeUsernameProblemLanguageResultExecution timeMemory
490993RainbowbunnyToys (CEOI18_toy)C++17
100 / 100
1162 ms11252 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 5005; int n; vector <int> Ans[MAXN]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; vector <int> Div; for(int i = 1; i * i <= n; i++) { if(n % i == 0) { Div.push_back(i); if(n != i * i) { Div.push_back(n / i); } } } sort(Div.begin(), Div.end()); for(int i = 0; i < (int)Div.size(); i++) { Ans[i].push_back(Div[i] - 1); for(int j = 1; j < i; j++) { if(Div[i] % Div[j]) { continue; } int tmp = Div[i] / Div[j] - 1; vector <int> tt; int pt0 = 0, pt1 = 0; while(pt0 < (int)Ans[i].size() and pt1 < (int)Ans[j].size()) { if(Ans[i][pt0] <= Ans[j][pt1] + tmp) { if(tt.empty() or tt.back() != Ans[i][pt0]) { tt.push_back(Ans[i][pt0]); } pt0++; } else { if(tt.empty() or tt.back() != Ans[j][pt1] + tmp) { tt.push_back(Ans[j][pt1] + tmp); } pt1++; } } while(pt0 < (int)Ans[i].size()) { if(tt.empty() or tt.back() != Ans[i][pt0]) { tt.push_back(Ans[i][pt0]); } pt0++; } while(pt1 < (int)Ans[j].size()) { if(tt.empty() or tt.back() != Ans[j][pt1] + tmp) { tt.push_back(Ans[j][pt1] + tmp); } pt1++; } Ans[i].swap(tt); } } cout << Ans[(int)Div.size() - 1].size() << '\n'; for(auto x : Ans[(int)Div.size() - 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...