#include <bits/stdc++.h> // Tomasz Nowak
using namespace std; // XIII LO Szczecin
using LL = long long; // Poland
#define FOR(i, l, r) for(int i = (l); i <= (r); ++i)
#define REP(i, n) FOR(i, 0, (n) - 1)
template<class T> int size(T &&x) {
return int(x.size());
}
template<class A, class B> ostream& operator<<(ostream &out, const pair<A, B> &p) {
return out << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {
out << '{';
for(auto it = x.begin(); it != x.end(); ++it)
out << *it << (it == prev(x.end()) ? "" : ", ");
return out << '}';
}
void dump() {}
template<class T, class... Args> void dump(T &&x, Args... args) {
cerr << x << "; ";
dump(args...);
}
#ifdef DEBUG
struct Nl{~Nl(){cerr << '\n';}};
# define debug(x...) cerr << (strcmp(#x, "") ? #x ": " : ""), dump(x), Nl(), cerr << ""
#else
# define debug(...) 0 && cerr
#endif
mt19937_64 rng(0);
int rd(int l, int r) {
return uniform_int_distribution<int>(l, r)(rng);
}
// end of templates
int n;
vector<int> curr_vec;
int curr_mul = 1;
set<int> answers;
bool can_mul(int a, int b) {
return a <= n / b and a * b <= n;
}
void backtrack() {
debug(curr_mul, curr_vec);
if(curr_mul == n) {
answers.emplace(accumulate(curr_vec.begin(), curr_vec.end(), 0));
return;
}
// add new
if(can_mul(curr_mul, 2)) {
curr_mul *= 2;
curr_vec.emplace_back(1);
backtrack();
curr_mul /= 2;
curr_vec.pop_back();
}
// increase last number
if(size(curr_vec) == 1 or (size(curr_vec) >= 2 and curr_vec.back() + 1 <= curr_vec.end()[-2]))
if(can_mul(curr_mul / (curr_vec.back() + 1), curr_vec.back() + 2)) {
curr_mul /= curr_vec.back() + 1;
++curr_vec.back();
curr_mul *= curr_vec.back() + 1;
backtrack();
curr_mul /= curr_vec.back() + 1;
--curr_vec.back();
curr_mul *= curr_vec.back() + 1;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
backtrack();
cout << size(answers) << '\n';
for(int a : answers)
cout << a << ' ';
cout << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
6 ms |
384 KB |
Output is correct |
19 |
Correct |
6 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
4 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
6 ms |
384 KB |
Output is correct |
19 |
Correct |
6 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
4 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
7 ms |
640 KB |
Output is correct |
27 |
Correct |
6 ms |
512 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
8 ms |
640 KB |
Output is correct |
32 |
Correct |
7 ms |
640 KB |
Output is correct |
33 |
Correct |
6 ms |
640 KB |
Output is correct |
34 |
Correct |
9 ms |
640 KB |
Output is correct |
35 |
Correct |
7 ms |
640 KB |
Output is correct |
36 |
Correct |
7 ms |
640 KB |
Output is correct |
37 |
Correct |
7 ms |
512 KB |
Output is correct |
38 |
Correct |
9 ms |
640 KB |
Output is correct |
39 |
Correct |
7 ms |
640 KB |
Output is correct |
40 |
Correct |
7 ms |
640 KB |
Output is correct |
41 |
Correct |
7 ms |
640 KB |
Output is correct |
42 |
Correct |
7 ms |
640 KB |
Output is correct |
43 |
Correct |
7 ms |
640 KB |
Output is correct |
44 |
Correct |
7 ms |
640 KB |
Output is correct |
45 |
Correct |
7 ms |
640 KB |
Output is correct |
46 |
Correct |
7 ms |
640 KB |
Output is correct |
47 |
Correct |
7 ms |
640 KB |
Output is correct |
48 |
Correct |
7 ms |
640 KB |
Output is correct |
49 |
Correct |
8 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
6 ms |
384 KB |
Output is correct |
19 |
Correct |
6 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
4 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
7 ms |
640 KB |
Output is correct |
27 |
Correct |
6 ms |
512 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
8 ms |
640 KB |
Output is correct |
32 |
Correct |
7 ms |
640 KB |
Output is correct |
33 |
Correct |
6 ms |
640 KB |
Output is correct |
34 |
Correct |
9 ms |
640 KB |
Output is correct |
35 |
Correct |
7 ms |
640 KB |
Output is correct |
36 |
Correct |
7 ms |
640 KB |
Output is correct |
37 |
Correct |
7 ms |
512 KB |
Output is correct |
38 |
Correct |
9 ms |
640 KB |
Output is correct |
39 |
Correct |
7 ms |
640 KB |
Output is correct |
40 |
Correct |
7 ms |
640 KB |
Output is correct |
41 |
Correct |
7 ms |
640 KB |
Output is correct |
42 |
Correct |
7 ms |
640 KB |
Output is correct |
43 |
Correct |
7 ms |
640 KB |
Output is correct |
44 |
Correct |
7 ms |
640 KB |
Output is correct |
45 |
Correct |
7 ms |
640 KB |
Output is correct |
46 |
Correct |
7 ms |
640 KB |
Output is correct |
47 |
Correct |
7 ms |
640 KB |
Output is correct |
48 |
Correct |
7 ms |
640 KB |
Output is correct |
49 |
Correct |
8 ms |
640 KB |
Output is correct |
50 |
Correct |
47 ms |
2936 KB |
Output is correct |
51 |
Correct |
30 ms |
2040 KB |
Output is correct |
52 |
Correct |
27 ms |
1912 KB |
Output is correct |
53 |
Correct |
24 ms |
1792 KB |
Output is correct |
54 |
Correct |
15 ms |
1280 KB |
Output is correct |
55 |
Correct |
53 ms |
3192 KB |
Output is correct |
56 |
Correct |
45 ms |
2936 KB |
Output is correct |
57 |
Correct |
42 ms |
2808 KB |
Output is correct |
58 |
Correct |
57 ms |
3452 KB |
Output is correct |
59 |
Correct |
55 ms |
3320 KB |
Output is correct |
60 |
Correct |
36 ms |
2552 KB |
Output is correct |
61 |
Correct |
52 ms |
3320 KB |
Output is correct |
62 |
Correct |
15 ms |
1280 KB |
Output is correct |
63 |
Correct |
58 ms |
3448 KB |
Output is correct |
64 |
Correct |
57 ms |
3448 KB |
Output is correct |
65 |
Correct |
51 ms |
3192 KB |
Output is correct |
66 |
Correct |
57 ms |
3448 KB |
Output is correct |
67 |
Correct |
58 ms |
3448 KB |
Output is correct |
68 |
Correct |
59 ms |
3448 KB |
Output is correct |
69 |
Correct |
57 ms |
3448 KB |
Output is correct |
70 |
Correct |
50 ms |
3224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
6 ms |
384 KB |
Output is correct |
19 |
Correct |
6 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
4 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
7 ms |
640 KB |
Output is correct |
27 |
Correct |
6 ms |
512 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
8 ms |
640 KB |
Output is correct |
32 |
Correct |
7 ms |
640 KB |
Output is correct |
33 |
Correct |
6 ms |
640 KB |
Output is correct |
34 |
Correct |
9 ms |
640 KB |
Output is correct |
35 |
Correct |
7 ms |
640 KB |
Output is correct |
36 |
Correct |
7 ms |
640 KB |
Output is correct |
37 |
Correct |
7 ms |
512 KB |
Output is correct |
38 |
Correct |
9 ms |
640 KB |
Output is correct |
39 |
Correct |
7 ms |
640 KB |
Output is correct |
40 |
Correct |
7 ms |
640 KB |
Output is correct |
41 |
Correct |
7 ms |
640 KB |
Output is correct |
42 |
Correct |
7 ms |
640 KB |
Output is correct |
43 |
Correct |
7 ms |
640 KB |
Output is correct |
44 |
Correct |
7 ms |
640 KB |
Output is correct |
45 |
Correct |
7 ms |
640 KB |
Output is correct |
46 |
Correct |
7 ms |
640 KB |
Output is correct |
47 |
Correct |
7 ms |
640 KB |
Output is correct |
48 |
Correct |
7 ms |
640 KB |
Output is correct |
49 |
Correct |
8 ms |
640 KB |
Output is correct |
50 |
Correct |
47 ms |
2936 KB |
Output is correct |
51 |
Correct |
30 ms |
2040 KB |
Output is correct |
52 |
Correct |
27 ms |
1912 KB |
Output is correct |
53 |
Correct |
24 ms |
1792 KB |
Output is correct |
54 |
Correct |
15 ms |
1280 KB |
Output is correct |
55 |
Correct |
53 ms |
3192 KB |
Output is correct |
56 |
Correct |
45 ms |
2936 KB |
Output is correct |
57 |
Correct |
42 ms |
2808 KB |
Output is correct |
58 |
Correct |
57 ms |
3452 KB |
Output is correct |
59 |
Correct |
55 ms |
3320 KB |
Output is correct |
60 |
Correct |
36 ms |
2552 KB |
Output is correct |
61 |
Correct |
52 ms |
3320 KB |
Output is correct |
62 |
Correct |
15 ms |
1280 KB |
Output is correct |
63 |
Correct |
58 ms |
3448 KB |
Output is correct |
64 |
Correct |
57 ms |
3448 KB |
Output is correct |
65 |
Correct |
51 ms |
3192 KB |
Output is correct |
66 |
Correct |
57 ms |
3448 KB |
Output is correct |
67 |
Correct |
58 ms |
3448 KB |
Output is correct |
68 |
Correct |
59 ms |
3448 KB |
Output is correct |
69 |
Correct |
57 ms |
3448 KB |
Output is correct |
70 |
Correct |
50 ms |
3224 KB |
Output is correct |
71 |
Execution timed out |
5066 ms |
764 KB |
Time limit exceeded |
72 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
6 ms |
384 KB |
Output is correct |
19 |
Correct |
6 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
4 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
7 ms |
640 KB |
Output is correct |
27 |
Correct |
6 ms |
512 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
8 ms |
640 KB |
Output is correct |
32 |
Correct |
7 ms |
640 KB |
Output is correct |
33 |
Correct |
6 ms |
640 KB |
Output is correct |
34 |
Correct |
9 ms |
640 KB |
Output is correct |
35 |
Correct |
7 ms |
640 KB |
Output is correct |
36 |
Correct |
7 ms |
640 KB |
Output is correct |
37 |
Correct |
7 ms |
512 KB |
Output is correct |
38 |
Correct |
9 ms |
640 KB |
Output is correct |
39 |
Correct |
7 ms |
640 KB |
Output is correct |
40 |
Correct |
7 ms |
640 KB |
Output is correct |
41 |
Correct |
7 ms |
640 KB |
Output is correct |
42 |
Correct |
7 ms |
640 KB |
Output is correct |
43 |
Correct |
7 ms |
640 KB |
Output is correct |
44 |
Correct |
7 ms |
640 KB |
Output is correct |
45 |
Correct |
7 ms |
640 KB |
Output is correct |
46 |
Correct |
7 ms |
640 KB |
Output is correct |
47 |
Correct |
7 ms |
640 KB |
Output is correct |
48 |
Correct |
7 ms |
640 KB |
Output is correct |
49 |
Correct |
8 ms |
640 KB |
Output is correct |
50 |
Correct |
47 ms |
2936 KB |
Output is correct |
51 |
Correct |
30 ms |
2040 KB |
Output is correct |
52 |
Correct |
27 ms |
1912 KB |
Output is correct |
53 |
Correct |
24 ms |
1792 KB |
Output is correct |
54 |
Correct |
15 ms |
1280 KB |
Output is correct |
55 |
Correct |
53 ms |
3192 KB |
Output is correct |
56 |
Correct |
45 ms |
2936 KB |
Output is correct |
57 |
Correct |
42 ms |
2808 KB |
Output is correct |
58 |
Correct |
57 ms |
3452 KB |
Output is correct |
59 |
Correct |
55 ms |
3320 KB |
Output is correct |
60 |
Correct |
36 ms |
2552 KB |
Output is correct |
61 |
Correct |
52 ms |
3320 KB |
Output is correct |
62 |
Correct |
15 ms |
1280 KB |
Output is correct |
63 |
Correct |
58 ms |
3448 KB |
Output is correct |
64 |
Correct |
57 ms |
3448 KB |
Output is correct |
65 |
Correct |
51 ms |
3192 KB |
Output is correct |
66 |
Correct |
57 ms |
3448 KB |
Output is correct |
67 |
Correct |
58 ms |
3448 KB |
Output is correct |
68 |
Correct |
59 ms |
3448 KB |
Output is correct |
69 |
Correct |
57 ms |
3448 KB |
Output is correct |
70 |
Correct |
50 ms |
3224 KB |
Output is correct |
71 |
Execution timed out |
5066 ms |
764 KB |
Time limit exceeded |
72 |
Halted |
0 ms |
0 KB |
- |