Submission #490968

#TimeUsernameProblemLanguageResultExecution timeMemory
490968Mike4235Toys (CEOI18_toy)C++17
79 / 100
5100 ms218176 KiB
#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> #define for1(i,a,b) for (int i = a; i <= b; i++) #define for2(i,a,b) for (int i = a; i >= b; i--) // #define int long long #define sz(a) (int)a.size() #define pii pair<int,int> #define pb push_back /* __builtin_popcountll(x) : Number of 1-bit __builtin_ctzll(x) : Number of trailing 0 */ const long double PI = 3.1415926535897932384626433832795; const int INF = 1000000000000000000; const int MOD = 1000000007; const int MOD2 = 1000000009; const long double EPS = 1e-6; using namespace std; const int MX = 1e6; int n; map<int, vector<pii>> mp; map<pii, bool> flag; set<int> se; vector<pii> d[MX + 5]; void solve(int x, int sum) { if (flag[{x, sum}]) return; flag[{x, sum}] = 1; se.insert(sum + x - 1); if (x <= MX) { for (auto p : d[x]) solve(p.first, sum + p.second - 1); return; } if (mp.find(x) != mp.end()) { for (auto p : mp[x]) solve(p.first, sum + p.second - 1); } else { for (int i = 2; i * i <= x; i++) if (x % i == 0) { if (i * i == x) { mp[x].push_back({i, i}); solve(i, sum + i - 1); } else { int j = x / i; mp[x].push_back({i, j}); mp[x].push_back({j, i}); solve(i, sum + j - 1); solve(j, sum + i - 1); } } } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // freopen("cf.inp", "r", stdin); // freopen("cf.out", "w", stdout); for1(i,1,MX) { for (int j = i * 2, cnt = 2; j <= MX; j += i, cnt++) d[j].push_back({i, cnt}); } cin >> n; solve(n, 0); cout << sz(se) << "\n"; for (auto x : se) cout << x << " "; }

Compilation message (stderr)

toy.cpp:21:17: warning: overflow in conversion from 'long int' to 'int' changes value from '1000000000000000000' to '-1486618624' [-Woverflow]
   21 | const int INF = 1000000000000000000;
      |                 ^~~~~~~~~~~~~~~~~~~
#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...