# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
104955 | eriksuenderhauf | Toys (CEOI18_toy) | C++11 | 3169 ms | 109816 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.
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%I64d", &(n))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,null_type,hash<int>> ht2;
typedef cc_hash_table<int,ht2,hash<int>> ht;
ht dp;
int di[100000];
int m = 0;
ht2 dfs(int n) {
if (dp.find(n) != dp.end())
return dp[n];
if (n == 1) {
ht2 sm;
sm.insert(0);
dp[n] = sm;
return sm;
}
ht2 ret;
ret.insert(n - 1);
for (int j = 0; j < m; j++) {
int i = di[j];
if (i * i > n)
break;
if (n % i != 0)
continue;
ht2 tmp = dfs(n / i);
auto it = tmp.begin();
for (; it != tmp.end(); it++)
ret.insert((*it) + i - 1);
}
dp[n] = ret;
return ret;
}
int main()
{
int n;
ni(n);
for (int i = 2; i * i <= n; i++)
if (n % i == 0)
di[m++] = i;
ht2 sm = dfs(n);
m = 0;
printf("%d\n", sm.size());
auto it = sm.begin();
for (; it != sm.end(); it++)
di[m++] = *it;
sort(di, di + m);
for (int i = 0; i < m; i++)
printf("%d ", di[i]);
enl;
return 0;
}
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... |