제출 #94238

#제출 시각아이디문제언어결과실행 시간메모리
94238jasony123123Toys (CEOI18_toy)C++11
100 / 100
2991 ms88460 KiB
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <array>
#include <unordered_map>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;

#define FOR(i,start,end) for(int i=start;i<(int)(end);i++)
#define FORE(i,start,end) for(int i=start;i<=(int)end;i++)
#define RFOR(i,start,end) for(int i = start; i>end; i--)
#define RFORE(i,start,end) for(int i = start; i>=end; i--)
#define all(a) a.begin(), a.end()
#define mt make_tuple
#define mp make_pair
#define v vector
#define sf scanf
#define pf printf
#define dvar(x) cout << #x << " := " << x << "\n"
#define darr(x,n) FOR(i,0,n) cout << #x << "[" << i << "]" << " := " << x[i] << "\n"

typedef long long ll;
typedef long double ld;
typedef pair<int, int > pii;
typedef pair<ll, ll> pll;
//template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> void minn(T &a, T b) { a = min(a, b); }
template<class T> void maxx(T &a, T b) { a = max(a, b); }

void io() {
#ifdef LOCAL_PROJECT 
	freopen("input.in", "r", stdin); freopen("output.out", "w", stdout);
#else 
	/* online submission */

#endif 
	ios_base::sync_with_stdio(false); cin.tie(NULL);
}

/*************************CEOI 2018 Day 2 P2 - Toy *************************/

v<int> fac;
v<v<int>> ff;
v<v<int>> nex;
v<set<int>> sums;

void combine(set<int> &scur, set<int> &sold, int add) {
	for (auto x : sold)
		scur.insert(x + add);
}

int main() {
	io();
	int n; cin >> n;
	for (int i = 1; i*i <= n; i++)
		if (n%i == 0) {
			fac.push_back(i);
			if (i*i != n) fac.push_back(n / i);
		}
	sort(all(fac));

	ff.resize(fac.size());
	ff[0] = {}, ff[fac.size() - 1] = fac;
	FOR(f, 1, fac.size() - 1) {
		for (auto j : fac) {
			if (j*j > fac[f]) break;
			if (fac[f] % j == 0) {
				ff[f].push_back(j);
				if (j*j != fac[f]) ff[f].push_back(fac[f] / j);
			}
		}
	//	sort(all(ff[f]));
	}

	nex.resize(fac.size());
	FOR(i, 0, ff.size()) {
		for (auto f : ff[i])
			nex[i].push_back(lower_bound(all(fac), fac[i] / f) - fac.begin());
	}

	sums.resize(fac.size());
	sums[0].insert(0);

	FOR(i, 1, sums.size())
		FOR(j, 1, nex[i].size())
		if (nex[i][j] != i)
			combine(sums[i], sums[nex[i][j]], ff[i][j] - 1);


	cout << sums.back().size() << "\n";
	for (auto x : sums.back()) cout << x << " ";
	cout << "\n";

/*	darr(fac, fac.size());
	FOR(i, 0, ff.size()) {
		cout << i << " factors: ";
		for (auto f : ff[i]) cout << f << ", ";
		cout << "\n";
	}
	FOR(i, 0, nex.size()) {
		cout << i << " nex idx: ";
		for (auto j : nex[i]) cout << j << ", ";
		cout << "\n";
	}*/
}
#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...