Submission #536897

#TimeUsernameProblemLanguageResultExecution timeMemory
536897zaneyuToys (CEOI18_toy)C++14
100 / 100
1037 ms22368 KiB
/*input 12 */ #include<bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0;i<n;i++) #define MNTO(x,y) x=min(x,y) #define REP1(i,n) for(int i=1;i<=n;i++) #define ll long long #define ld long double #define sz(x) (int)x.size() #define pb push_back #define unq(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) const int maxn=2e4+5; map<int,vector<int>> dp; vector<int> rec(int n){ if(dp.count(n)) return dp[n]; vector<int> vv={n-1}; if(n==1){ return vv; } for(int i=2;i<=sqrt(n);i++){ if(n%i==0){ auto z=rec(n/i); for(int a:z) vv.pb(a+(i-1)); } } unq(vv); return dp[n]=vv; } int main(){ ios::sync_with_stdio(false),cin.tie(0); int n; cin>>n; auto z=rec(n); unq(z); cout<<sz(z)<<'\n'; for(int x:z) cout<<x<<' '; }
#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...