답안 #490977

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
490977 2021-11-30T02:37:52 Z hollwo_pelw Toys (CEOI18_toy) C++17
100 / 100
3702 ms 4844 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> d;
set<int> res;

inline int getpos(int a) {
    return lower_bound(d.begin(), d.end(), a) - d.begin();
}

void backtrack(int val, int cur, int sum = 0) {
    if (val == 1)
        return res.insert(sum), (void) 0;
    if (cur == d.size()) return ;
    
    int x = d[cur];
    
    if (val < x) return ;
    if (val == x)
        return backtrack(val / x, cur + 1, sum + x - 1);
    
    backtrack(val, cur + 1, sum);
    while (val % x == 0) {
        val /= x, sum += x - 1;
        backtrack(val, cur + 1, sum);
    }
}

signed main() {
	cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
	int n; cin >> n;
	for (int i = 2; i * i <= n; i++) {
	    if (n % i == 0) {
	        d.push_back(i);
	        if (n / i != i)
	            d.push_back(n / i);
	    }
	}
	sort(d.begin(), d.end());
	
	backtrack(n, 0);
	
	res.insert(n - 1);
	
	cout << res.size() << '\n';
	for (auto v : res)
	    cout << v << ' ';
}

Compilation message

toy.cpp: In function 'void backtrack(int, int, int)':
toy.cpp:14:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     if (cur == d.size()) return ;
      |         ~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 208 KB Output is correct
25 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 208 KB Output is correct
25 Correct 0 ms 208 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 2 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 1 ms 216 KB Output is correct
34 Correct 0 ms 216 KB Output is correct
35 Correct 2 ms 216 KB Output is correct
36 Correct 0 ms 216 KB Output is correct
37 Correct 1 ms 220 KB Output is correct
38 Correct 1 ms 216 KB Output is correct
39 Correct 0 ms 216 KB Output is correct
40 Correct 0 ms 216 KB Output is correct
41 Correct 0 ms 216 KB Output is correct
42 Correct 2 ms 216 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 0 ms 204 KB Output is correct
45 Correct 0 ms 204 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 208 KB Output is correct
25 Correct 0 ms 208 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 2 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 1 ms 216 KB Output is correct
34 Correct 0 ms 216 KB Output is correct
35 Correct 2 ms 216 KB Output is correct
36 Correct 0 ms 216 KB Output is correct
37 Correct 1 ms 220 KB Output is correct
38 Correct 1 ms 216 KB Output is correct
39 Correct 0 ms 216 KB Output is correct
40 Correct 0 ms 216 KB Output is correct
41 Correct 0 ms 216 KB Output is correct
42 Correct 2 ms 216 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 0 ms 204 KB Output is correct
45 Correct 0 ms 204 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 0 ms 204 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 1 ms 332 KB Output is correct
53 Correct 1 ms 332 KB Output is correct
54 Correct 1 ms 204 KB Output is correct
55 Correct 1 ms 332 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 0 ms 204 KB Output is correct
59 Correct 0 ms 204 KB Output is correct
60 Correct 0 ms 204 KB Output is correct
61 Correct 3 ms 332 KB Output is correct
62 Correct 0 ms 204 KB Output is correct
63 Correct 1 ms 204 KB Output is correct
64 Correct 0 ms 204 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Correct 0 ms 204 KB Output is correct
67 Correct 0 ms 204 KB Output is correct
68 Correct 0 ms 204 KB Output is correct
69 Correct 0 ms 204 KB Output is correct
70 Correct 2 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 208 KB Output is correct
25 Correct 0 ms 208 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 2 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 1 ms 216 KB Output is correct
34 Correct 0 ms 216 KB Output is correct
35 Correct 2 ms 216 KB Output is correct
36 Correct 0 ms 216 KB Output is correct
37 Correct 1 ms 220 KB Output is correct
38 Correct 1 ms 216 KB Output is correct
39 Correct 0 ms 216 KB Output is correct
40 Correct 0 ms 216 KB Output is correct
41 Correct 0 ms 216 KB Output is correct
42 Correct 2 ms 216 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 0 ms 204 KB Output is correct
45 Correct 0 ms 204 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 0 ms 204 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 1 ms 332 KB Output is correct
53 Correct 1 ms 332 KB Output is correct
54 Correct 1 ms 204 KB Output is correct
55 Correct 1 ms 332 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 0 ms 204 KB Output is correct
59 Correct 0 ms 204 KB Output is correct
60 Correct 0 ms 204 KB Output is correct
61 Correct 3 ms 332 KB Output is correct
62 Correct 0 ms 204 KB Output is correct
63 Correct 1 ms 204 KB Output is correct
64 Correct 0 ms 204 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Correct 0 ms 204 KB Output is correct
67 Correct 0 ms 204 KB Output is correct
68 Correct 0 ms 204 KB Output is correct
69 Correct 0 ms 204 KB Output is correct
70 Correct 2 ms 204 KB Output is correct
71 Correct 319 ms 1424 KB Output is correct
72 Correct 175 ms 1176 KB Output is correct
73 Correct 287 ms 1224 KB Output is correct
74 Correct 140 ms 1004 KB Output is correct
75 Correct 158 ms 996 KB Output is correct
76 Correct 566 ms 1860 KB Output is correct
77 Correct 500 ms 1560 KB Output is correct
78 Correct 390 ms 1584 KB Output is correct
79 Correct 382 ms 1484 KB Output is correct
80 Correct 1 ms 204 KB Output is correct
81 Correct 0 ms 204 KB Output is correct
82 Correct 1 ms 332 KB Output is correct
83 Correct 16 ms 620 KB Output is correct
84 Correct 24 ms 596 KB Output is correct
85 Correct 3 ms 460 KB Output is correct
86 Correct 1 ms 204 KB Output is correct
87 Correct 23 ms 708 KB Output is correct
88 Correct 0 ms 204 KB Output is correct
89 Correct 0 ms 204 KB Output is correct
90 Correct 0 ms 204 KB Output is correct
91 Correct 8 ms 480 KB Output is correct
92 Correct 47 ms 928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 208 KB Output is correct
25 Correct 0 ms 208 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 2 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 1 ms 216 KB Output is correct
34 Correct 0 ms 216 KB Output is correct
35 Correct 2 ms 216 KB Output is correct
36 Correct 0 ms 216 KB Output is correct
37 Correct 1 ms 220 KB Output is correct
38 Correct 1 ms 216 KB Output is correct
39 Correct 0 ms 216 KB Output is correct
40 Correct 0 ms 216 KB Output is correct
41 Correct 0 ms 216 KB Output is correct
42 Correct 2 ms 216 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 0 ms 204 KB Output is correct
45 Correct 0 ms 204 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 0 ms 204 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 1 ms 332 KB Output is correct
53 Correct 1 ms 332 KB Output is correct
54 Correct 1 ms 204 KB Output is correct
55 Correct 1 ms 332 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 0 ms 204 KB Output is correct
59 Correct 0 ms 204 KB Output is correct
60 Correct 0 ms 204 KB Output is correct
61 Correct 3 ms 332 KB Output is correct
62 Correct 0 ms 204 KB Output is correct
63 Correct 1 ms 204 KB Output is correct
64 Correct 0 ms 204 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Correct 0 ms 204 KB Output is correct
67 Correct 0 ms 204 KB Output is correct
68 Correct 0 ms 204 KB Output is correct
69 Correct 0 ms 204 KB Output is correct
70 Correct 2 ms 204 KB Output is correct
71 Correct 319 ms 1424 KB Output is correct
72 Correct 175 ms 1176 KB Output is correct
73 Correct 287 ms 1224 KB Output is correct
74 Correct 140 ms 1004 KB Output is correct
75 Correct 158 ms 996 KB Output is correct
76 Correct 566 ms 1860 KB Output is correct
77 Correct 500 ms 1560 KB Output is correct
78 Correct 390 ms 1584 KB Output is correct
79 Correct 382 ms 1484 KB Output is correct
80 Correct 1 ms 204 KB Output is correct
81 Correct 0 ms 204 KB Output is correct
82 Correct 1 ms 332 KB Output is correct
83 Correct 16 ms 620 KB Output is correct
84 Correct 24 ms 596 KB Output is correct
85 Correct 3 ms 460 KB Output is correct
86 Correct 1 ms 204 KB Output is correct
87 Correct 23 ms 708 KB Output is correct
88 Correct 0 ms 204 KB Output is correct
89 Correct 0 ms 204 KB Output is correct
90 Correct 0 ms 204 KB Output is correct
91 Correct 8 ms 480 KB Output is correct
92 Correct 47 ms 928 KB Output is correct
93 Correct 2871 ms 4036 KB Output is correct
94 Correct 1189 ms 3476 KB Output is correct
95 Correct 1542 ms 3308 KB Output is correct
96 Correct 1313 ms 3020 KB Output is correct
97 Correct 1168 ms 2780 KB Output is correct
98 Correct 3303 ms 4844 KB Output is correct
99 Correct 3702 ms 4608 KB Output is correct
100 Correct 3205 ms 4320 KB Output is correct
101 Correct 3159 ms 4168 KB Output is correct
102 Correct 2609 ms 3968 KB Output is correct
103 Correct 1707 ms 3740 KB Output is correct
104 Correct 1 ms 312 KB Output is correct
105 Correct 1 ms 204 KB Output is correct
106 Correct 1 ms 308 KB Output is correct
107 Correct 72 ms 1192 KB Output is correct
108 Correct 239 ms 1812 KB Output is correct
109 Correct 8 ms 700 KB Output is correct
110 Correct 1 ms 204 KB Output is correct
111 Correct 80 ms 1352 KB Output is correct
112 Correct 1 ms 204 KB Output is correct
113 Correct 1 ms 204 KB Output is correct
114 Correct 2 ms 332 KB Output is correct
115 Correct 1 ms 204 KB Output is correct
116 Correct 5 ms 460 KB Output is correct
117 Correct 291 ms 2304 KB Output is correct