Submission #267138

# Submission time Handle Problem Language Result Execution time Memory
267138 2020-08-15T21:28:21 Z peuch Toys (CEOI18_toy) C++17
79 / 100
5000 ms 8540 KB
#include<bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")


const int MAXN = 2e4;
 
int n;
int cnt;
int v[MAXN], qnt[MAXN];
 
vector<int> ans;
map<int, vector<int> > dp, divisor;
 
void getDiv(int num);
void calcDP(int num);
int fexp(int a, int exp);

int main(){
	scanf("%d", &n);
	calcDP(n);
	sort(ans.begin(), ans.end());
	printf("%lu\n", ans.size());
	for(int i = 0; i < ans.size(); i++)
		printf("%d ", ans[i]);
	printf("\n");
}
 
void getDiv(int num){
	if(!divisor[num].empty()) return;
	divisor[num].push_back(1);
	if(num == 1) return;
	int x = num;
	int aux = 0;
	vector<int> m, q;
	for(int i = 2; i * i <= num; i++){
		if(x % i == 0){
			int exp = 0;
			while(x % i == 0) aux++, exp++, x /= i;
			m.push_back(i);
			q.push_back(exp);
		}
	}
	if(x != 1){
		m.push_back(x);
		q.push_back(1);
		aux++;
	}
	if(aux == 1){
		divisor[num].push_back(num);
		return;
	}
	if(m.size() == 1){
		getDiv(num / m[0]);
		divisor[num] = divisor[num / m[0]];
		divisor[num].push_back(num);	
		return;
	}
	int mult = 1;
	int aux1 = 0;
	for(int i = 0; i < m.size() - 1; i++){
		aux1 += q[i];
		mult *= fexp(m[i], q[i]);
		if(2 * aux1 >= aux){
			getDiv(mult);
			getDiv(num / mult);
			for(int j = 0; j < divisor[mult].size(); j++){
				for(int k = 0; k < divisor[num / mult].size(); k++){
					if(k == 0 && j == 0) continue;
					int val = divisor[mult][j] * divisor[num / mult][k];
					divisor[num].push_back(val);
				}
			}
			return;
		}
	}
	aux1 = 0;
	mult = 1;
	for(int i = m.size() - 1; i >= 0; i--){
		aux1 += q[i];
		mult *= fexp(m[i], q[i]);
		if(2 * aux1 >= aux){
			getDiv(mult);
			getDiv(num / mult);
			for(int j = 0; j < divisor[mult].size(); j++){
				for(int k = 0; k < divisor[num / mult].size(); k++){
					if(k == 0 && j == 0) continue;
					int val = divisor[mult][j] * divisor[num / mult][k];
					divisor[num].push_back(val);
				}
			}
			return;
		}
	}
}
 
void calcDP(int num){
	if(!dp[num].empty()){
		ans = dp[num];
		return;
	}
	getDiv(num);
	vector<int> aux = divisor[num];
	vector<int> ret;
	ret.push_back(num - 1);
	vector<int> aux1, aux2;
	map<int, bool> marc;
	for(int i = 0; i < aux.size(); i++){
		if(aux[i] == num || aux[i] == 1) continue;
		if(num / aux[i] < aux[i]) continue;
		calcDP(aux[i]);
		aux1 = ans;
		calcDP(num / aux[i]);
		aux2 = ans;
		for(int i1 = 0; i1 < aux1.size(); i1++){
			for( int i2 = 0; i2 < aux2.size(); i2++){
				if(marc[aux1[i1] + aux2[i2]]) continue;
				ret.push_back(aux1[i1] + aux2[i2]);
				marc[aux1[i1] + aux2[i2]] = 1;
			}
		}
	}
	ans = ret;
	dp[num] = ans;
}

int fexp(int a, int exp){
	int ret = 1;
	for(int k = 30; k >= 0; k--){
		ret *= ret;
		if((1 << k) & exp) ret *= a;
	}
	return ret;
}

Compilation message

toy.cpp:4: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    4 | #pragma GCC optimization ("O3")
      | 
toy.cpp:5: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    5 | #pragma GCC optimization ("unroll-loops")
      | 
toy.cpp: In function 'int main()':
toy.cpp:26:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |  for(int i = 0; i < ans.size(); i++)
      |                 ~~^~~~~~~~~~~~
toy.cpp: In function 'void getDiv(int)':
toy.cpp:63:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |  for(int i = 0; i < m.size() - 1; i++){
      |                 ~~^~~~~~~~~~~~~~
toy.cpp:69:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |    for(int j = 0; j < divisor[mult].size(); j++){
      |                   ~~^~~~~~~~~~~~~~~~~~~~~~
toy.cpp:70:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |     for(int k = 0; k < divisor[num / mult].size(); k++){
      |                    ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
toy.cpp:87:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |    for(int j = 0; j < divisor[mult].size(); j++){
      |                   ~~^~~~~~~~~~~~~~~~~~~~~~
toy.cpp:88:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |     for(int k = 0; k < divisor[num / mult].size(); k++){
      |                    ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
toy.cpp: In function 'void calcDP(int)':
toy.cpp:110:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |  for(int i = 0; i < aux.size(); i++){
      |                 ~~^~~~~~~~~~~~
toy.cpp:117:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |   for(int i1 = 0; i1 < aux1.size(); i1++){
      |                   ~~~^~~~~~~~~~~~~
toy.cpp:118:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  118 |    for( int i2 = 0; i2 < aux2.size(); i2++){
      |                     ~~~^~~~~~~~~~~~~
toy.cpp: In function 'int main()':
toy.cpp:22:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   22 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 0 ms 256 KB Output is correct
22 Correct 1 ms 256 KB Output is correct
23 Correct 0 ms 256 KB Output is correct
24 Correct 0 ms 256 KB Output is correct
25 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 0 ms 256 KB Output is correct
22 Correct 1 ms 256 KB Output is correct
23 Correct 0 ms 256 KB Output is correct
24 Correct 0 ms 256 KB Output is correct
25 Correct 0 ms 256 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 416 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 2 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 0 ms 256 KB Output is correct
35 Correct 0 ms 256 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 0 ms 256 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 256 KB Output is correct
42 Correct 1 ms 256 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 256 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 1 ms 256 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 0 ms 256 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 0 ms 256 KB Output is correct
22 Correct 1 ms 256 KB Output is correct
23 Correct 0 ms 256 KB Output is correct
24 Correct 0 ms 256 KB Output is correct
25 Correct 0 ms 256 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 416 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 2 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 0 ms 256 KB Output is correct
35 Correct 0 ms 256 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 0 ms 256 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 256 KB Output is correct
42 Correct 1 ms 256 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 256 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 1 ms 256 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 0 ms 256 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 7 ms 416 KB Output is correct
51 Correct 5 ms 384 KB Output is correct
52 Correct 6 ms 384 KB Output is correct
53 Correct 5 ms 384 KB Output is correct
54 Correct 3 ms 384 KB Output is correct
55 Correct 10 ms 512 KB Output is correct
56 Correct 9 ms 512 KB Output is correct
57 Correct 7 ms 384 KB Output is correct
58 Correct 0 ms 256 KB Output is correct
59 Correct 1 ms 256 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 5 ms 384 KB Output is correct
62 Correct 2 ms 384 KB Output is correct
63 Correct 1 ms 384 KB Output is correct
64 Correct 1 ms 256 KB Output is correct
65 Correct 4 ms 384 KB Output is correct
66 Correct 0 ms 256 KB Output is correct
67 Correct 0 ms 256 KB Output is correct
68 Correct 1 ms 384 KB Output is correct
69 Correct 1 ms 384 KB Output is correct
70 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 0 ms 256 KB Output is correct
22 Correct 1 ms 256 KB Output is correct
23 Correct 0 ms 256 KB Output is correct
24 Correct 0 ms 256 KB Output is correct
25 Correct 0 ms 256 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 416 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 2 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 0 ms 256 KB Output is correct
35 Correct 0 ms 256 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 0 ms 256 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 256 KB Output is correct
42 Correct 1 ms 256 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 256 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 1 ms 256 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 0 ms 256 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 7 ms 416 KB Output is correct
51 Correct 5 ms 384 KB Output is correct
52 Correct 6 ms 384 KB Output is correct
53 Correct 5 ms 384 KB Output is correct
54 Correct 3 ms 384 KB Output is correct
55 Correct 10 ms 512 KB Output is correct
56 Correct 9 ms 512 KB Output is correct
57 Correct 7 ms 384 KB Output is correct
58 Correct 0 ms 256 KB Output is correct
59 Correct 1 ms 256 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 5 ms 384 KB Output is correct
62 Correct 2 ms 384 KB Output is correct
63 Correct 1 ms 384 KB Output is correct
64 Correct 1 ms 256 KB Output is correct
65 Correct 4 ms 384 KB Output is correct
66 Correct 0 ms 256 KB Output is correct
67 Correct 0 ms 256 KB Output is correct
68 Correct 1 ms 384 KB Output is correct
69 Correct 1 ms 384 KB Output is correct
70 Correct 2 ms 384 KB Output is correct
71 Correct 1748 ms 4876 KB Output is correct
72 Correct 1012 ms 3928 KB Output is correct
73 Correct 1900 ms 4476 KB Output is correct
74 Correct 712 ms 3064 KB Output is correct
75 Correct 999 ms 3320 KB Output is correct
76 Correct 3783 ms 6388 KB Output is correct
77 Correct 4263 ms 6060 KB Output is correct
78 Correct 2896 ms 5368 KB Output is correct
79 Correct 3049 ms 5576 KB Output is correct
80 Correct 1 ms 288 KB Output is correct
81 Correct 0 ms 256 KB Output is correct
82 Correct 15 ms 384 KB Output is correct
83 Correct 365 ms 1208 KB Output is correct
84 Correct 343 ms 1656 KB Output is correct
85 Correct 53 ms 764 KB Output is correct
86 Correct 1 ms 384 KB Output is correct
87 Correct 378 ms 1912 KB Output is correct
88 Correct 1 ms 256 KB Output is correct
89 Correct 0 ms 384 KB Output is correct
90 Correct 1 ms 384 KB Output is correct
91 Correct 45 ms 1024 KB Output is correct
92 Correct 248 ms 2040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 0 ms 256 KB Output is correct
22 Correct 1 ms 256 KB Output is correct
23 Correct 0 ms 256 KB Output is correct
24 Correct 0 ms 256 KB Output is correct
25 Correct 0 ms 256 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 416 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 2 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 0 ms 256 KB Output is correct
35 Correct 0 ms 256 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 0 ms 256 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 256 KB Output is correct
42 Correct 1 ms 256 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 256 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 1 ms 256 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 0 ms 256 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 7 ms 416 KB Output is correct
51 Correct 5 ms 384 KB Output is correct
52 Correct 6 ms 384 KB Output is correct
53 Correct 5 ms 384 KB Output is correct
54 Correct 3 ms 384 KB Output is correct
55 Correct 10 ms 512 KB Output is correct
56 Correct 9 ms 512 KB Output is correct
57 Correct 7 ms 384 KB Output is correct
58 Correct 0 ms 256 KB Output is correct
59 Correct 1 ms 256 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 5 ms 384 KB Output is correct
62 Correct 2 ms 384 KB Output is correct
63 Correct 1 ms 384 KB Output is correct
64 Correct 1 ms 256 KB Output is correct
65 Correct 4 ms 384 KB Output is correct
66 Correct 0 ms 256 KB Output is correct
67 Correct 0 ms 256 KB Output is correct
68 Correct 1 ms 384 KB Output is correct
69 Correct 1 ms 384 KB Output is correct
70 Correct 2 ms 384 KB Output is correct
71 Correct 1748 ms 4876 KB Output is correct
72 Correct 1012 ms 3928 KB Output is correct
73 Correct 1900 ms 4476 KB Output is correct
74 Correct 712 ms 3064 KB Output is correct
75 Correct 999 ms 3320 KB Output is correct
76 Correct 3783 ms 6388 KB Output is correct
77 Correct 4263 ms 6060 KB Output is correct
78 Correct 2896 ms 5368 KB Output is correct
79 Correct 3049 ms 5576 KB Output is correct
80 Correct 1 ms 288 KB Output is correct
81 Correct 0 ms 256 KB Output is correct
82 Correct 15 ms 384 KB Output is correct
83 Correct 365 ms 1208 KB Output is correct
84 Correct 343 ms 1656 KB Output is correct
85 Correct 53 ms 764 KB Output is correct
86 Correct 1 ms 384 KB Output is correct
87 Correct 378 ms 1912 KB Output is correct
88 Correct 1 ms 256 KB Output is correct
89 Correct 0 ms 384 KB Output is correct
90 Correct 1 ms 384 KB Output is correct
91 Correct 45 ms 1024 KB Output is correct
92 Correct 248 ms 2040 KB Output is correct
93 Execution timed out 5056 ms 8540 KB Time limit exceeded
94 Halted 0 ms 0 KB -