Submission #406350

#TimeUsernameProblemLanguageResultExecution timeMemory
406350abdzagToys (CEOI18_toy)C++17
100 / 100
935 ms60484 KiB
#include<bits/stdc++.h> #include<unordered_map> #define rep(i,a,b) for(int i=int(a);i<int(b);i++) #define rrep(i,a,b) for(int i=int(a);i>int(b);i--) #define all(v) v.begin(),v.end() #define trav(a,v) for(auto&a:v) #define sz(a) a.size() typedef long double ld; using namespace std; const long long inf = 1e15; typedef long long ll; typedef unsigned long long ull; struct Deleter { void operator () (int* ptr) { delete ptr; } }; int main() { cin.sync_with_stdio(false); vector<int> primes; primes.push_back(2); rep(i, 3, 4e4) { ll val = sqrt(i); bool done = true; rep(j, 0, primes.size()) { if (i % primes[j] == 0) { done = false; break; } if (primes[j] * primes[j] > i)break; } if (done) { primes.push_back(i); } } ll n; cin >> n; ll cur = n; if (n == 1){ cout <<1<<endl<< 0 << endl; return 0; } vector<int> v; rep(i, 0, primes.size()) { if (cur % primes[i] == 0) { v.push_back(primes[i]); cur /= primes[i]; i--; } } ll last = 1; if (cur != 1) { v.push_back(cur); } else { last = v.back(); v.pop_back(); } set<vector<int>> dp; set<vector<int>> dp0; vector<int> vv; dp0.insert(vv); trav(fac, v) { trav(vec, dp0) { rep(i, 0, vec.size()) { vector<int> next = vec; next[i] *= fac; sort(all(next)); dp.insert(next); } vector<int> next = vec; next.push_back(fac); sort(all(next)); dp.insert(next); } dp.swap(dp0); dp.clear(); } set<int> ans; trav(vec, dp0) { ll val = 0; ll val0 = 0; vector<int> ny = vec; ny.push_back(1); trav(a, vec) { val += a - 1; } val0 = val; trav(a, ny) { val += (last - 1) * a; ans.insert(val); val = val0; } } cout << ans.size() << endl; trav(a, ans)cout << a << " "; return 0; }

Compilation message (stderr)

toy.cpp: In function 'int main()':
toy.cpp:25:6: warning: unused variable 'val' [-Wunused-variable]
   25 |   ll val = sqrt(i);
      |      ^~~
#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...