Submission #147758

#TimeUsernameProblemLanguageResultExecution timeMemory
14775812tqianToys (CEOI18_toy)C++14
79 / 100
5009 ms5384 KiB
#pragma comment(linker, "/stack:200000000") //#pragma GCC optimize("Ofast") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; const double PI = 4 * atan(1); #define sz(x) (int)(x).size() #define ll long long #define ld long double #define mp make_pair #define pb push_back #define eb emplace_back #define pii pair <int, int> #define vi vector<int> #define f first #define s second #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define vpi vector<pair<int, int>> #define vpd vector<pair<double, double>> #define pd pair<double, double> #define f0r(i,a) for(int i=0;i<a;i++) #define f1r(i,a,b) for(int i=a;i<b;i++) #define trav(a, x) for (auto& a : x) template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; } template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) { cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]"; } void fast_io(){ ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); } void io(string taskname){ string fin = taskname + ".in"; string fout = taskname + ".out"; const char* FIN = fin.c_str(); const char* FOUT = fout.c_str(); freopen(FIN, "r", stdin); freopen(FOUT, "w", stdout); fast_io(); } const int MAX = 1500; const int INF = 1e9 + 7; set<int> ans; set<int> s; unordered_map<int, int> um; vi divisors; vi nums[MAX]; ///index of the divisor, find largest divisor of d less than or ///equal to mx int get(int d, int mx){ int l = 0; int r = sz(nums[d])-1; while(abs(l-r)>1){ int m = (l + r)/2; if(nums[d][m]>mx){ r = m-1; } else{ l = m; } } if(l>r) swap(l, r); if(nums[d][r] <= mx) return r; return l; } void solve(int left, int last, int sum){ if(left == 1){ ans.insert(sum); return; } int id = um[left]; int idx = get(id, last); f1r(i, 1, idx+1){ int divisor = nums[id][i]; solve(left/divisors[divisor], divisors[divisor], sum + divisors[divisor] - 1); } } int main(){ fast_io(); int n; cin >> n; f1r(i, 1, sqrt(n) + 1){ if(n%i == 0){ s.insert(i); s.insert(n/i); } } for(auto x: s) divisors.eb(x); f0r(i, sz(divisors)){ um[divisors[i]] = i; f0r(j, i+1){ if(divisors[i]%divisors[j] == 0){ nums[i].eb(j); } } } solve(n, INF, 0); cout << sz(ans) << endl; for(auto x: ans) cout << x << " "; cout << endl; return 0; }

Compilation message (stderr)

toy.cpp:1:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker, "/stack:200000000")
 
toy.cpp: In function 'void io(std::__cxx11::string)':
toy.cpp:52:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen(FIN, "r", stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~
toy.cpp:53:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen(FOUT, "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...