# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1260804 | Bui_Quoc_Cuong | Toys (CEOI18_toy) | C++20 | 5097 ms | 84180 KiB |
#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
bool maximize(A &a, const B b) {
if (a < b) {
a = b;
return true;
} return false;
}
template <class A, class B>
bool minimize(A &a, const B b) {
if (a > b) {
a = b;
return true;
} return false;
}
#define pb push_back
#define FOR(i, a, b) for(int i = a; i <= (int)b; i++)
#define FORD(i, a, b) for(int i = a; i >= (int)b; i--)
#define fi first
#define se second
#define ALL(A) A.begin(), A.end()
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef long long ll;
const int N = 3e5 + 5;
const int oo = 2e9 + 29032008;
const ll INF = 1e18 + 29032008;
int n;
map <int, int> dp[1360];
int newpos[1360][1360];
void solve() {
cin >> n;
vector <int> v;
for (int i = 1; i * i <= n; i++) if (n % i == 0) {
v.push_back(i);
if (n / i != i) v.push_back(n / i);
}
sort(ALL(v));
memset(newpos, - 1, sizeof newpos);
for (int i = 0; i < (int)v.size(); i++) {
for (int j = 0; j < (int)v.size(); j++) {
if (1LL * v[i] * v[j] > n) break;
if (n % (v[i] * v[j]) != 0) continue;
int pos = lower_bound(ALL(v), v[i] * v[j]) - v.begin();
newpos[i][j] = newpos[j][i] = pos;
}
}
dp[0][0] = 1;
for (int i = 0; i < (int)v.size(); i++) {
for (auto &x : dp[i]) {
for (int j = 0; j < (int)v.size(); j++) {
if (newpos[i][j] != - 1) dp[newpos[i][j]][x.first + v[j] - 1] = 1;
}
}
}
cout << dp[(int)v.size() - 1].size() << "\n";
for (auto &x : dp[(int)v.size() - 1]) cout << x.first << " ";
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define ko "kieuoanh"
if (fopen(ko".inp", "r")) {
freopen(ko".inp", "r", stdin);
freopen(ko".out", "w", stdout);
}
int NTEST = 1; // cin >> NTEST;
while (NTEST--) solve();
cerr << "\n[Time Elapsed] " << 0.001 * clock() << "s\n";
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... |