Submission #425028

#TimeUsernameProblemLanguageResultExecution timeMemory
425028Runtime_error_Toys (CEOI18_toy)C++14
79 / 100
5040 ms2648 KiB
#include <bits/stdc++.h> #define pb push_back #define pi pair<int,int> using namespace std; vector<pair<int,int> > pf; int n; vector<int> power[109],ans; map<int,int> mp; void bt(vector<int> last,vector<int> cur,int SumBefore,int curnum,bool larger){ bool IsEnd = cur.empty(); for(auto o:pf) if(o.second) IsEnd = 0; if(IsEnd){ if(mp.find(SumBefore) == mp.end()) ans.pb(SumBefore),mp[SumBefore]; return ; } int Divisor = cur.size(); for(int i=(larger?0:last[Divisor]);i<=pf[Divisor].second;i++){ cur.pb(i); curnum*= power[Divisor][i]; pf[Divisor].second -= i; if(cur.size() == pf.size() && curnum>1) bt(cur,{},SumBefore+curnum-1,1,0); else if(cur.size() < pf.size()) bt(last,cur,SumBefore,curnum,larger |(i>last[Divisor] ) ); curnum /= power[Divisor][i]; cur.pop_back(); pf[Divisor].second += i; } } signed main(){ cin>>n; for(int i=2;i<=n/i;i++){ int cnt = 0; while( (n%i) == 0) cnt++,n/=i; if(cnt > 0){ pf.pb(pi(i,cnt)); power[ pf.size()-1 ].pb(1); for(int j=1;j<=cnt;j++) power[ pf.size()-1 ].pb( power[ pf.size()-1 ].back()*i ); } } if(n != 1){ pf.pb(pi(n,1)); power[ pf.size()-1 ].pb(1); for(int j=1;j<=1;j++) power[ pf.size()-1 ].pb( power[ pf.size()-1 ].back()*n ); } sort(pf.begin(),pf.end()); // for(auto o:pf) // cout<<o.first<<" "<<o.second<<endl; vector<int> ls(pf.size(),0); bt(ls,{},0,1,0); sort(ans.begin(),ans.end()); printf("%d\n",(int)ans.size()); for(auto o:ans) printf("%d\n",o); }
#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...