# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
237710 | Nucleist | Toys (CEOI18_toy) | C++14 | 1383 ms | 45308 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define EPS 0.000001
struct greateri
{
template<class T>
bool operator()(T const &a, T const &b) const { return a > b; }
};
void setIO(string s) {
ios_base::sync_with_stdio(0); cin.tie(0);
freopen((s+".in").c_str(),"r",stdin);
freopen((s+".out").c_str(),"w",stdout);
}
struct HASH{
size_t operator()(const pair<int,int>&x)const{
return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
}
};
unordered_map<ll,ve>kol;
unordered_map<ll,vector<ll>>dp;
vector<ll> rec(ll n){
if(dp.find(n)!=dp.end())return dp[n];
vector<ll> ans;
if(kol.find(n)==kol.end()){
ve divi;
for (ll i = 2; i <= sqrt(n); ++i)
{
if(!(n%i)){
divi.pb(i);
divi.pb(n/i);
vector<ll> curi=rec(n/i);
for(auto it:curi)ans.pb(it+(i-1));
vector<ll> curi1=rec(i);
for(auto it:curi1)ans.pb(it+(n/i-1));
}
}
//sort(all(divi));
kol[n]=divi;
}
else{
for(auto it:kol[n]){
vector<ll> cur=rec(n/it);
for(auto it1:cur)ans.pb(it1+it-1);
}
}
ans.pb(n-1);
sort(all(ans));
ll last=-1;
ve raj;
for (int i = 0; i < ans.size(); ++i)
{
if(ans[i]!=last){
last=ans[i];
raj.pb(ans[i]);
}
}
return dp[n]=raj;
}
int main()
{
flash;
ll n;
cin>>n;
vector<ll>ans=rec(n);
cout<<ans.size()<<'\n';
for (auto it:ans)
{
cout<<it<<" ";
}
return 0;
}
//code the AC sol !
// BS/queue/map
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |