Submission #237710

#TimeUsernameProblemLanguageResultExecution timeMemory
237710NucleistToys (CEOI18_toy)C++14
100 / 100
1383 ms45308 KiB
#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)

toy.cpp:4:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("O3")
 
toy.cpp:5:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("unroll-loops")
 
toy.cpp: In function 'std::vector<long long int> rec(long long int)':
toy.cpp:66:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < ans.size(); ++i)
                   ~~^~~~~~~~~~~~
toy.cpp: In function 'void setIO(std::__cxx11::string)':
toy.cpp:27:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen((s+".in").c_str(),"r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
toy.cpp:28:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen((s+".out").c_str(),"w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...