Submission #161598

# Submission time Handle Problem Language Result Execution time Memory
161598 2019-11-03T08:35:49 Z oolimry Toys (CEOI18_toy) C++14
100 / 100
4003 ms 91040 KB
#include <bits/stdc++.h>

using namespace std;

bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;

    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;

    return true;
}

int p;
bool comp(int x, int y){
	int xx = 0;
	int yy = 0;
	while(x % p == 0){
		xx++;
		x /= p;
	}
	while(y % p == 0){
		yy++;
		y /= p;
	}
	return xx < yy;
}

vector<vector<int> > adj;
set<int> memo[2000];
vector<int> factors;


int main(){
	int n;
	cin >> n;
	
	vector<int> primes;
	for(int i = 1;i <= min(n,100000);i++){
		if(n % i == 0){
			factors.push_back(i);
			factors.push_back(n/i);
		}
	}
	sort(factors.begin(),factors.end());
	factors.erase(unique(factors.begin(),factors.end()),factors.end());
	
	for(int x : factors){
		if(isPrime(x)) primes.push_back(x);
	}
	
	for(int pp : primes){
		p = pp;
		stable_sort(factors.begin(),factors.end(),comp);
	}
	for(int i = 0;i < (int) factors.size();i++){
		vector<int> v;
		adj.push_back(v);
	}
	memo[0].insert({0});
	for(int i = 0;i < (int) factors.size();i++){
		for(int j = i+1;j < (int) factors.size();j++){
			int x = factors[i];
			int y = factors[j];
			if(y % x == 0){
				if(true){
					adj[j].push_back(i);
				}
			}
		}
	}
	set<int> answer = memo[0];
	for(int i = 1;i < (int) factors.size();i++){
		for(int j : adj[i]){
			int c = factors[i] / factors[j] - 1;
			for(int v : memo[j]){
				memo[i].insert(v + c);
			}
		}
		answer = memo[i];
	}
	
	
	//sort(answer.begin(),answer.end());
	//answer.erase(unique(answer.begin(),answer.end()),answer.end());
	cout << answer.size() << "\n";
	for(int x : answer){
		cout << x << " ";
	}
	
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 4 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 4 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 3 ms 504 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 2 ms 504 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 508 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 3 ms 380 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 504 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 3 ms 504 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 504 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 3 ms 504 KB Output is correct
48 Correct 2 ms 376 KB Output is correct
49 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 4 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 3 ms 504 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 2 ms 504 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 508 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 3 ms 380 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 504 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 3 ms 504 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 504 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 3 ms 504 KB Output is correct
48 Correct 2 ms 376 KB Output is correct
49 Correct 2 ms 504 KB Output is correct
50 Correct 6 ms 760 KB Output is correct
51 Correct 5 ms 760 KB Output is correct
52 Correct 6 ms 760 KB Output is correct
53 Correct 5 ms 632 KB Output is correct
54 Correct 4 ms 632 KB Output is correct
55 Correct 8 ms 888 KB Output is correct
56 Correct 7 ms 888 KB Output is correct
57 Correct 7 ms 760 KB Output is correct
58 Correct 2 ms 456 KB Output is correct
59 Correct 3 ms 380 KB Output is correct
60 Correct 3 ms 504 KB Output is correct
61 Correct 5 ms 632 KB Output is correct
62 Correct 3 ms 504 KB Output is correct
63 Correct 3 ms 504 KB Output is correct
64 Correct 3 ms 376 KB Output is correct
65 Correct 5 ms 632 KB Output is correct
66 Correct 2 ms 376 KB Output is correct
67 Correct 3 ms 376 KB Output is correct
68 Correct 4 ms 376 KB Output is correct
69 Correct 3 ms 508 KB Output is correct
70 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 4 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 3 ms 504 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 2 ms 504 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 508 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 3 ms 380 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 504 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 3 ms 504 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 504 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 3 ms 504 KB Output is correct
48 Correct 2 ms 376 KB Output is correct
49 Correct 2 ms 504 KB Output is correct
50 Correct 6 ms 760 KB Output is correct
51 Correct 5 ms 760 KB Output is correct
52 Correct 6 ms 760 KB Output is correct
53 Correct 5 ms 632 KB Output is correct
54 Correct 4 ms 632 KB Output is correct
55 Correct 8 ms 888 KB Output is correct
56 Correct 7 ms 888 KB Output is correct
57 Correct 7 ms 760 KB Output is correct
58 Correct 2 ms 456 KB Output is correct
59 Correct 3 ms 380 KB Output is correct
60 Correct 3 ms 504 KB Output is correct
61 Correct 5 ms 632 KB Output is correct
62 Correct 3 ms 504 KB Output is correct
63 Correct 3 ms 504 KB Output is correct
64 Correct 3 ms 376 KB Output is correct
65 Correct 5 ms 632 KB Output is correct
66 Correct 2 ms 376 KB Output is correct
67 Correct 3 ms 376 KB Output is correct
68 Correct 4 ms 376 KB Output is correct
69 Correct 3 ms 508 KB Output is correct
70 Correct 3 ms 504 KB Output is correct
71 Correct 514 ms 19972 KB Output is correct
72 Correct 357 ms 15352 KB Output is correct
73 Correct 490 ms 17784 KB Output is correct
74 Correct 269 ms 12048 KB Output is correct
75 Correct 315 ms 12796 KB Output is correct
76 Correct 816 ms 26616 KB Output is correct
77 Correct 775 ms 23416 KB Output is correct
78 Correct 659 ms 22000 KB Output is correct
79 Correct 645 ms 21388 KB Output is correct
80 Correct 3 ms 376 KB Output is correct
81 Correct 3 ms 376 KB Output is correct
82 Correct 6 ms 760 KB Output is correct
83 Correct 71 ms 4080 KB Output is correct
84 Correct 134 ms 4956 KB Output is correct
85 Correct 20 ms 1784 KB Output is correct
86 Correct 3 ms 376 KB Output is correct
87 Correct 105 ms 5552 KB Output is correct
88 Correct 3 ms 380 KB Output is correct
89 Correct 3 ms 376 KB Output is correct
90 Correct 3 ms 504 KB Output is correct
91 Correct 28 ms 2652 KB Output is correct
92 Correct 165 ms 7464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 4 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 3 ms 504 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 2 ms 504 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 508 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 3 ms 380 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 504 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 3 ms 504 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 504 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 3 ms 504 KB Output is correct
48 Correct 2 ms 376 KB Output is correct
49 Correct 2 ms 504 KB Output is correct
50 Correct 6 ms 760 KB Output is correct
51 Correct 5 ms 760 KB Output is correct
52 Correct 6 ms 760 KB Output is correct
53 Correct 5 ms 632 KB Output is correct
54 Correct 4 ms 632 KB Output is correct
55 Correct 8 ms 888 KB Output is correct
56 Correct 7 ms 888 KB Output is correct
57 Correct 7 ms 760 KB Output is correct
58 Correct 2 ms 456 KB Output is correct
59 Correct 3 ms 380 KB Output is correct
60 Correct 3 ms 504 KB Output is correct
61 Correct 5 ms 632 KB Output is correct
62 Correct 3 ms 504 KB Output is correct
63 Correct 3 ms 504 KB Output is correct
64 Correct 3 ms 376 KB Output is correct
65 Correct 5 ms 632 KB Output is correct
66 Correct 2 ms 376 KB Output is correct
67 Correct 3 ms 376 KB Output is correct
68 Correct 4 ms 376 KB Output is correct
69 Correct 3 ms 508 KB Output is correct
70 Correct 3 ms 504 KB Output is correct
71 Correct 514 ms 19972 KB Output is correct
72 Correct 357 ms 15352 KB Output is correct
73 Correct 490 ms 17784 KB Output is correct
74 Correct 269 ms 12048 KB Output is correct
75 Correct 315 ms 12796 KB Output is correct
76 Correct 816 ms 26616 KB Output is correct
77 Correct 775 ms 23416 KB Output is correct
78 Correct 659 ms 22000 KB Output is correct
79 Correct 645 ms 21388 KB Output is correct
80 Correct 3 ms 376 KB Output is correct
81 Correct 3 ms 376 KB Output is correct
82 Correct 6 ms 760 KB Output is correct
83 Correct 71 ms 4080 KB Output is correct
84 Correct 134 ms 4956 KB Output is correct
85 Correct 20 ms 1784 KB Output is correct
86 Correct 3 ms 376 KB Output is correct
87 Correct 105 ms 5552 KB Output is correct
88 Correct 3 ms 380 KB Output is correct
89 Correct 3 ms 376 KB Output is correct
90 Correct 3 ms 504 KB Output is correct
91 Correct 28 ms 2652 KB Output is correct
92 Correct 165 ms 7464 KB Output is correct
93 Correct 3160 ms 81544 KB Output is correct
94 Correct 1785 ms 55424 KB Output is correct
95 Correct 2068 ms 58084 KB Output is correct
96 Correct 1790 ms 51908 KB Output is correct
97 Correct 1663 ms 47224 KB Output is correct
98 Correct 3717 ms 89816 KB Output is correct
99 Correct 4003 ms 91040 KB Output is correct
100 Correct 3575 ms 87624 KB Output is correct
101 Correct 3410 ms 81136 KB Output is correct
102 Correct 2961 ms 73268 KB Output is correct
103 Correct 2312 ms 66024 KB Output is correct
104 Correct 3 ms 376 KB Output is correct
105 Correct 3 ms 376 KB Output is correct
106 Correct 10 ms 1148 KB Output is correct
107 Correct 230 ms 10468 KB Output is correct
108 Correct 612 ms 22264 KB Output is correct
109 Correct 51 ms 3704 KB Output is correct
110 Correct 3 ms 504 KB Output is correct
111 Correct 291 ms 13216 KB Output is correct
112 Correct 3 ms 376 KB Output is correct
113 Correct 3 ms 376 KB Output is correct
114 Correct 11 ms 1144 KB Output is correct
115 Correct 2 ms 376 KB Output is correct
116 Correct 22 ms 2040 KB Output is correct
117 Correct 605 ms 26784 KB Output is correct