Submission #305127

# Submission time Handle Problem Language Result Execution time Memory
305127 2020-09-22T15:40:17 Z miss_robot Toys (CEOI18_toy) C++14
100 / 100
979 ms 79900 KB
#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")

using namespace std;

int n;

unordered_map<string, unordered_set<int>> dp;
unordered_map<string, int> prod;
vector<int> p;
string c;

void smaller(int i, string& t, string& r){
	if(i == n){
		int s = prod[t]/prod[r]-1;
		unordered_set<int> *tmp1 = &dp[r], *tmp2 = &dp[t];
		for(int x : *tmp1) tmp2->insert(x+s);
		return;
	}
	for(int j = t[i]; j >= 0; j--){
		r.push_back(j);
		smaller(i+1, t, r);
		r.pop_back();
	}
}

void solve(int i, string& t){
	if(i == n){
		string r="";
		smaller(0, t, r);
		return;
	}
	for(int j = 0; j <= c[i]; j++){
		t.push_back(j);
		solve(i+1, t);
		t.pop_back();
	}
}

void pre(int i, int s, string &t){
	if(i == n){
		prod[t] = s;
		return;
	}
	for(int j = 0; j <= c[i]; j++){
		t.push_back(j);
		pre(i+1, s, t);
		s *= p[i];
		t.pop_back();
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cin >> n;
	int temp = sqrt(n);
	for(int i = 2; i <= temp; i++){
		if(!(n%i)) p.push_back(i), c.push_back(0);
		while(!(n%i)){
			c.back()++;
			n /= i;
		}
	}
	if(n > 1) p.push_back(n), c.push_back(1);
	n = p.size();
	string t(n, 0);
	dp[t].insert(0);
	t="";
	pre(0, 1, t);
	solve(0, t);
	vector<int> sol(dp[c].begin(), dp[c].end());
	sort(sol.begin(), sol.end());
	cout << sol.size() << "\n";
	for(int x : sol) cout << x << " ";
	cout << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 392 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 392 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 0 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 392 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 0 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 2 ms 640 KB Output is correct
51 Correct 2 ms 640 KB Output is correct
52 Correct 2 ms 640 KB Output is correct
53 Correct 2 ms 512 KB Output is correct
54 Correct 1 ms 512 KB Output is correct
55 Correct 3 ms 640 KB Output is correct
56 Correct 2 ms 640 KB Output is correct
57 Correct 2 ms 640 KB Output is correct
58 Correct 0 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 2 ms 512 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 1 ms 384 KB Output is correct
64 Correct 1 ms 384 KB Output is correct
65 Correct 2 ms 512 KB Output is correct
66 Correct 1 ms 384 KB Output is correct
67 Correct 1 ms 384 KB Output is correct
68 Correct 1 ms 384 KB Output is correct
69 Correct 1 ms 384 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 392 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 0 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 2 ms 640 KB Output is correct
51 Correct 2 ms 640 KB Output is correct
52 Correct 2 ms 640 KB Output is correct
53 Correct 2 ms 512 KB Output is correct
54 Correct 1 ms 512 KB Output is correct
55 Correct 3 ms 640 KB Output is correct
56 Correct 2 ms 640 KB Output is correct
57 Correct 2 ms 640 KB Output is correct
58 Correct 0 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 2 ms 512 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 1 ms 384 KB Output is correct
64 Correct 1 ms 384 KB Output is correct
65 Correct 2 ms 512 KB Output is correct
66 Correct 1 ms 384 KB Output is correct
67 Correct 1 ms 384 KB Output is correct
68 Correct 1 ms 384 KB Output is correct
69 Correct 1 ms 384 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
71 Correct 145 ms 17048 KB Output is correct
72 Correct 104 ms 13176 KB Output is correct
73 Correct 133 ms 15352 KB Output is correct
74 Correct 83 ms 10360 KB Output is correct
75 Correct 90 ms 11000 KB Output is correct
76 Correct 218 ms 22996 KB Output is correct
77 Correct 194 ms 20344 KB Output is correct
78 Correct 173 ms 19064 KB Output is correct
79 Correct 168 ms 18552 KB Output is correct
80 Correct 1 ms 384 KB Output is correct
81 Correct 1 ms 384 KB Output is correct
82 Correct 2 ms 640 KB Output is correct
83 Correct 18 ms 3328 KB Output is correct
84 Correct 25 ms 4216 KB Output is correct
85 Correct 6 ms 1408 KB Output is correct
86 Correct 1 ms 384 KB Output is correct
87 Correct 29 ms 4736 KB Output is correct
88 Correct 1 ms 384 KB Output is correct
89 Correct 1 ms 384 KB Output is correct
90 Correct 1 ms 384 KB Output is correct
91 Correct 10 ms 2048 KB Output is correct
92 Correct 40 ms 6136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 392 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 0 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 2 ms 640 KB Output is correct
51 Correct 2 ms 640 KB Output is correct
52 Correct 2 ms 640 KB Output is correct
53 Correct 2 ms 512 KB Output is correct
54 Correct 1 ms 512 KB Output is correct
55 Correct 3 ms 640 KB Output is correct
56 Correct 2 ms 640 KB Output is correct
57 Correct 2 ms 640 KB Output is correct
58 Correct 0 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 2 ms 512 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 1 ms 384 KB Output is correct
64 Correct 1 ms 384 KB Output is correct
65 Correct 2 ms 512 KB Output is correct
66 Correct 1 ms 384 KB Output is correct
67 Correct 1 ms 384 KB Output is correct
68 Correct 1 ms 384 KB Output is correct
69 Correct 1 ms 384 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
71 Correct 145 ms 17048 KB Output is correct
72 Correct 104 ms 13176 KB Output is correct
73 Correct 133 ms 15352 KB Output is correct
74 Correct 83 ms 10360 KB Output is correct
75 Correct 90 ms 11000 KB Output is correct
76 Correct 218 ms 22996 KB Output is correct
77 Correct 194 ms 20344 KB Output is correct
78 Correct 173 ms 19064 KB Output is correct
79 Correct 168 ms 18552 KB Output is correct
80 Correct 1 ms 384 KB Output is correct
81 Correct 1 ms 384 KB Output is correct
82 Correct 2 ms 640 KB Output is correct
83 Correct 18 ms 3328 KB Output is correct
84 Correct 25 ms 4216 KB Output is correct
85 Correct 6 ms 1408 KB Output is correct
86 Correct 1 ms 384 KB Output is correct
87 Correct 29 ms 4736 KB Output is correct
88 Correct 1 ms 384 KB Output is correct
89 Correct 1 ms 384 KB Output is correct
90 Correct 1 ms 384 KB Output is correct
91 Correct 10 ms 2048 KB Output is correct
92 Correct 40 ms 6136 KB Output is correct
93 Correct 837 ms 71492 KB Output is correct
94 Correct 489 ms 48132 KB Output is correct
95 Correct 526 ms 50540 KB Output is correct
96 Correct 466 ms 44932 KB Output is correct
97 Correct 419 ms 40964 KB Output is correct
98 Correct 948 ms 78452 KB Output is correct
99 Correct 979 ms 79900 KB Output is correct
100 Correct 920 ms 76704 KB Output is correct
101 Correct 856 ms 71068 KB Output is correct
102 Correct 745 ms 64028 KB Output is correct
103 Correct 632 ms 57628 KB Output is correct
104 Correct 1 ms 384 KB Output is correct
105 Correct 1 ms 384 KB Output is correct
106 Correct 3 ms 896 KB Output is correct
107 Correct 64 ms 8952 KB Output is correct
108 Correct 158 ms 18812 KB Output is correct
109 Correct 16 ms 3072 KB Output is correct
110 Correct 1 ms 384 KB Output is correct
111 Correct 85 ms 11128 KB Output is correct
112 Correct 1 ms 384 KB Output is correct
113 Correct 1 ms 384 KB Output is correct
114 Correct 4 ms 896 KB Output is correct
115 Correct 1 ms 384 KB Output is correct
116 Correct 8 ms 1664 KB Output is correct
117 Correct 181 ms 22800 KB Output is correct