답안 #331455

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
331455 2020-11-28T14:24:51 Z davitmarg Toys (CEOI18_toy) C++17
100 / 100
1455 ms 69912 KB
/*
DavitMarg
In a honky-tonk,
Down in Mexico
*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <random>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
#define fastIO ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int N = 1005;

int n;
set<int> ans;
map<int, set<int>> dp[N];
map<int, int> used[N];

set<int> add(set<int> a,int d)
{
	set<int> s;
	for (auto it = a.begin(); it != a.end(); ++it)
		s.insert(*it + d);
	return s;
}


void add(set<int> &a, set<int> b)
{
	a.insert(all(b));
}


int sq(int x)
{
	return sqrt(x);
}

void dfs(int num, int mx)
{
	if (mx > num)
	{
		used[mx][num] = used[num][num];
		dp[mx][num] = dp[num][num];
	}
	if (used[mx][num])
		return;
	used[mx][num] = 1;
	for (int i = 1; i * i <= num; i++)
	{
		if (num % i)
			continue;
		if (i <= mx && i != 1)
		{
			dfs(num / i, min(i,num/i));
			add(dp[mx][num], add(dp[min(i, num / i)][num / i], i - 1));
		}
		if (num / i <= mx && i != num / i)
		{
			dfs(i, min(i, num / i));
			add(dp[mx][num], add(dp[min(i, num / i)][i], num/i - 1));
		}
	}
}

int main()
{
	fastIO;
	cin >> n;
	used[1][1] = 1;
	dp[1][1].insert(0);

	for (int i = 1; i * i <= n; i++)
	{
		if (n % i)
			continue;

		int P = i;
		for (int j = 1; j * j <= n / P; j++)
		{
			if ((n / P) % j)
				continue;

			int p = j;

			if (p != 1 && p <= P)
			{
				dfs(n / P / p, min(p, n / P / p));
				add(ans, add(dp[min(p, n / P / p)][n / P / p], P + p - 2));
			}


			p = n / P / p;
			if (p != 1 && p <= P)
			{
				dfs(n / P / p, min(p, n / P / p));
				add(ans, add(dp[min(p, n / P / p)][n / P / p], P + p - 2));
			}

		}


		P = n / P;
		if (P * P == n)
			continue;
		for (int j = 1; j * j <= n / P; j++)
		{
			if ((n / P) % j)
				continue;

			int p = j;

			if (p != 1 && p <= P)
			{
				dfs(n / P / p, min(p, n / P / p));
				add(ans, add(dp[min(p, n / P / p)][n / P / p], P + p - 2));
			}


			p = n / P / p;
			if (p != 1 && p <= P)
			{
				dfs(n / P / p, min(p, n / P / p));
				add(ans, add(dp[min(p, n / P / p)][n / P / p], P + p - 2));
			}

		}
	}
	ans.insert(n - 1);
	cout << ans.size() << endl;
	for (auto it = ans.begin(); it != ans.end(); ++it)
		cout << (*it) << " ";
	cout << endl;
	return 0;
}
/*

100000000


67108864

3
1 2
1 3

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 492 KB Output is correct
37 Correct 1 ms 492 KB Output is correct
38 Correct 1 ms 492 KB Output is correct
39 Correct 1 ms 492 KB Output is correct
40 Correct 1 ms 492 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 492 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 620 KB Output is correct
46 Correct 1 ms 492 KB Output is correct
47 Correct 1 ms 492 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 492 KB Output is correct
37 Correct 1 ms 492 KB Output is correct
38 Correct 1 ms 492 KB Output is correct
39 Correct 1 ms 492 KB Output is correct
40 Correct 1 ms 492 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 492 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 620 KB Output is correct
46 Correct 1 ms 492 KB Output is correct
47 Correct 1 ms 492 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 492 KB Output is correct
50 Correct 4 ms 620 KB Output is correct
51 Correct 3 ms 620 KB Output is correct
52 Correct 3 ms 636 KB Output is correct
53 Correct 2 ms 620 KB Output is correct
54 Correct 2 ms 512 KB Output is correct
55 Correct 3 ms 748 KB Output is correct
56 Correct 3 ms 620 KB Output is correct
57 Correct 3 ms 620 KB Output is correct
58 Correct 1 ms 640 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 1 ms 640 KB Output is correct
61 Correct 2 ms 492 KB Output is correct
62 Correct 1 ms 492 KB Output is correct
63 Correct 1 ms 492 KB Output is correct
64 Correct 1 ms 492 KB Output is correct
65 Correct 2 ms 492 KB Output is correct
66 Correct 1 ms 364 KB Output is correct
67 Correct 1 ms 364 KB Output is correct
68 Correct 1 ms 492 KB Output is correct
69 Correct 1 ms 492 KB Output is correct
70 Correct 2 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 492 KB Output is correct
37 Correct 1 ms 492 KB Output is correct
38 Correct 1 ms 492 KB Output is correct
39 Correct 1 ms 492 KB Output is correct
40 Correct 1 ms 492 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 492 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 620 KB Output is correct
46 Correct 1 ms 492 KB Output is correct
47 Correct 1 ms 492 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 492 KB Output is correct
50 Correct 4 ms 620 KB Output is correct
51 Correct 3 ms 620 KB Output is correct
52 Correct 3 ms 636 KB Output is correct
53 Correct 2 ms 620 KB Output is correct
54 Correct 2 ms 512 KB Output is correct
55 Correct 3 ms 748 KB Output is correct
56 Correct 3 ms 620 KB Output is correct
57 Correct 3 ms 620 KB Output is correct
58 Correct 1 ms 640 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 1 ms 640 KB Output is correct
61 Correct 2 ms 492 KB Output is correct
62 Correct 1 ms 492 KB Output is correct
63 Correct 1 ms 492 KB Output is correct
64 Correct 1 ms 492 KB Output is correct
65 Correct 2 ms 492 KB Output is correct
66 Correct 1 ms 364 KB Output is correct
67 Correct 1 ms 364 KB Output is correct
68 Correct 1 ms 492 KB Output is correct
69 Correct 1 ms 492 KB Output is correct
70 Correct 2 ms 492 KB Output is correct
71 Correct 179 ms 11628 KB Output is correct
72 Correct 123 ms 8556 KB Output is correct
73 Correct 185 ms 11884 KB Output is correct
74 Correct 95 ms 6912 KB Output is correct
75 Correct 113 ms 8044 KB Output is correct
76 Correct 317 ms 18804 KB Output is correct
77 Correct 294 ms 17644 KB Output is correct
78 Correct 235 ms 14792 KB Output is correct
79 Correct 225 ms 14700 KB Output is correct
80 Correct 1 ms 492 KB Output is correct
81 Correct 1 ms 492 KB Output is correct
82 Correct 3 ms 620 KB Output is correct
83 Correct 22 ms 2156 KB Output is correct
84 Correct 29 ms 2668 KB Output is correct
85 Correct 7 ms 1004 KB Output is correct
86 Correct 2 ms 620 KB Output is correct
87 Correct 37 ms 2668 KB Output is correct
88 Correct 1 ms 492 KB Output is correct
89 Correct 1 ms 492 KB Output is correct
90 Correct 2 ms 492 KB Output is correct
91 Correct 12 ms 1260 KB Output is correct
92 Correct 52 ms 3692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 492 KB Output is correct
37 Correct 1 ms 492 KB Output is correct
38 Correct 1 ms 492 KB Output is correct
39 Correct 1 ms 492 KB Output is correct
40 Correct 1 ms 492 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 492 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 620 KB Output is correct
46 Correct 1 ms 492 KB Output is correct
47 Correct 1 ms 492 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 492 KB Output is correct
50 Correct 4 ms 620 KB Output is correct
51 Correct 3 ms 620 KB Output is correct
52 Correct 3 ms 636 KB Output is correct
53 Correct 2 ms 620 KB Output is correct
54 Correct 2 ms 512 KB Output is correct
55 Correct 3 ms 748 KB Output is correct
56 Correct 3 ms 620 KB Output is correct
57 Correct 3 ms 620 KB Output is correct
58 Correct 1 ms 640 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 1 ms 640 KB Output is correct
61 Correct 2 ms 492 KB Output is correct
62 Correct 1 ms 492 KB Output is correct
63 Correct 1 ms 492 KB Output is correct
64 Correct 1 ms 492 KB Output is correct
65 Correct 2 ms 492 KB Output is correct
66 Correct 1 ms 364 KB Output is correct
67 Correct 1 ms 364 KB Output is correct
68 Correct 1 ms 492 KB Output is correct
69 Correct 1 ms 492 KB Output is correct
70 Correct 2 ms 492 KB Output is correct
71 Correct 179 ms 11628 KB Output is correct
72 Correct 123 ms 8556 KB Output is correct
73 Correct 185 ms 11884 KB Output is correct
74 Correct 95 ms 6912 KB Output is correct
75 Correct 113 ms 8044 KB Output is correct
76 Correct 317 ms 18804 KB Output is correct
77 Correct 294 ms 17644 KB Output is correct
78 Correct 235 ms 14792 KB Output is correct
79 Correct 225 ms 14700 KB Output is correct
80 Correct 1 ms 492 KB Output is correct
81 Correct 1 ms 492 KB Output is correct
82 Correct 3 ms 620 KB Output is correct
83 Correct 22 ms 2156 KB Output is correct
84 Correct 29 ms 2668 KB Output is correct
85 Correct 7 ms 1004 KB Output is correct
86 Correct 2 ms 620 KB Output is correct
87 Correct 37 ms 2668 KB Output is correct
88 Correct 1 ms 492 KB Output is correct
89 Correct 1 ms 492 KB Output is correct
90 Correct 2 ms 492 KB Output is correct
91 Correct 12 ms 1260 KB Output is correct
92 Correct 52 ms 3692 KB Output is correct
93 Correct 1182 ms 57196 KB Output is correct
94 Correct 579 ms 31212 KB Output is correct
95 Correct 700 ms 37484 KB Output is correct
96 Correct 589 ms 33896 KB Output is correct
97 Correct 534 ms 31084 KB Output is correct
98 Correct 1188 ms 62944 KB Output is correct
99 Correct 1455 ms 69912 KB Output is correct
100 Correct 1193 ms 62780 KB Output is correct
101 Correct 1225 ms 60656 KB Output is correct
102 Correct 1074 ms 52932 KB Output is correct
103 Correct 725 ms 38892 KB Output is correct
104 Correct 2 ms 492 KB Output is correct
105 Correct 2 ms 492 KB Output is correct
106 Correct 6 ms 748 KB Output is correct
107 Correct 67 ms 4972 KB Output is correct
108 Correct 179 ms 11244 KB Output is correct
109 Correct 19 ms 1644 KB Output is correct
110 Correct 3 ms 492 KB Output is correct
111 Correct 81 ms 5740 KB Output is correct
112 Correct 2 ms 492 KB Output is correct
113 Correct 2 ms 492 KB Output is correct
114 Correct 11 ms 748 KB Output is correct
115 Correct 2 ms 492 KB Output is correct
116 Correct 16 ms 1004 KB Output is correct
117 Correct 210 ms 12084 KB Output is correct