Submission #536916

# Submission time Handle Problem Language Result Execution time Memory
536916 2022-03-14T07:27:29 Z squiddy Toys (CEOI18_toy) C++14
100 / 100
436 ms 11780 KB
#include <bits/stdc++.h>
#define fast_input ios_base::sync_with_stdio(0); cin.tie(0);

using namespace std;
#define ii pair<int, int>
#define iii pair<int, ii>
#define ll long long
#define ull unsigned long long
#define pq priority_queue
#define FOR(v, s, e) for (int v = s; v < e; v++)
#define FOR_REV(v, s, e) for (int v = e - 1; v >= s; v--)
#define make_ii(a, b) make_pair(a, b)
#define make_iii(a, b, c) make_pair(a, make_pair(b, c))
#define fi first
#define se second
//#define int long long

int n, n_mod, fac = 2, ct;
vector<ii> pfac;
vector<int> factors;
vector<vector<ii>> adj_list;
vector<vector<int>> multiply;
set<int> answers;

void create_tree(int curr, int l_idx, int curr_idx) {
    if (curr == n) return;
    if (adj_list[curr_idx].size() != 0) return;
    FOR(i, l_idx, factors.size()) {
        int factor = factors[i];
        if (factor == 1) continue;
        int new_factor = curr * factor;
        if (curr > n / factor) return;
        if (n % new_factor == 0 && (n / new_factor >= factor || n == new_factor)) {
            int nidx = multiply[curr_idx][i];
            adj_list[curr_idx].emplace_back(factor, nidx);
            create_tree(new_factor, i, nidx);
        }
    }
}

void dp_factors(int idx, int curr) {
    if (idx == pfac.size()) {
        factors.push_back(curr);
        return;
    }
    ii factor = pfac[idx];
    int c_exp = 1;
    FOR(i, 0, factor.se + 1) {
        dp_factors(idx + 1, curr * c_exp);
        c_exp *= factor.fi;
    }
}

void dfs(int nd, int c_sum, int c_total, int l_factor) {
    if (c_total == n) {
        answers.insert(c_sum);
        return;
    }
    for(ii node : adj_list[nd]) {
        if (node.fi < l_factor) continue;
        dfs(node.se, c_sum + node.fi - 1, c_total * node.fi, max(node.fi, l_factor));
    }
}

int32_t main() {
    fast_input;
    cin >> n;
    n_mod = n;
    while (fac * fac <= n_mod) {
        ct = 0;
        for (;n_mod % fac == 0;ct++) {
            n_mod = n_mod / fac;
        }
        if (ct != 0) {
            pfac.emplace_back(fac, ct);
        }
        fac++;
    }
    if (n_mod != 1) pfac.emplace_back(n_mod, 1);
    // build factors
    dp_factors(0, 1);
    sort(factors.begin(), factors.end());
    multiply.resize(factors.size());
    FOR(i, 0, factors.size()) {
        multiply[i].resize(factors.size());
        FOR(j, 0, factors.size()) {
            if ((n / factors[i]) % factors[j] == 0) {
                multiply[i][j] = lower_bound(factors.begin(), factors.end(), factors[i] * factors[j]) - factors.begin();
            }
        }
    }
    adj_list.resize(factors.size());
    create_tree(1, 0, 0);
    dfs(0, 0, 1, 1);
    cout << answers.size() << '\n';
    for(int answer: answers) {
        cout << answer << ' ';
    }
}

Compilation message

toy.cpp: In function 'void create_tree(int, int, int)':
toy.cpp:10:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 | #define FOR(v, s, e) for (int v = s; v < e; v++)
......
   28 |     FOR(i, l_idx, factors.size()) {
      |         ~~~~~~~~~~~~~~~~~~~~~~~~        
toy.cpp:28:5: note: in expansion of macro 'FOR'
   28 |     FOR(i, l_idx, factors.size()) {
      |     ^~~
toy.cpp: In function 'void dp_factors(int, int)':
toy.cpp:42:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     if (idx == pfac.size()) {
      |         ~~~~^~~~~~~~~~~~~~
toy.cpp: In function 'int32_t main()':
toy.cpp:10:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 | #define FOR(v, s, e) for (int v = s; v < e; v++)
......
   84 |     FOR(i, 0, factors.size()) {
      |         ~~~~~~~~~~~~~~~~~~~~            
toy.cpp:84:5: note: in expansion of macro 'FOR'
   84 |     FOR(i, 0, factors.size()) {
      |     ^~~
toy.cpp:10:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 | #define FOR(v, s, e) for (int v = s; v < e; v++)
......
   86 |         FOR(j, 0, factors.size()) {
      |             ~~~~~~~~~~~~~~~~~~~~        
toy.cpp:86:9: note: in expansion of macro 'FOR'
   86 |         FOR(j, 0, factors.size()) {
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 340 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 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 0 ms 340 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 1 ms 372 KB Output is correct
66 Correct 0 ms 212 KB Output is correct
67 Correct 0 ms 212 KB Output is correct
68 Correct 0 ms 212 KB Output is correct
69 Correct 1 ms 212 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 340 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 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 0 ms 340 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 1 ms 372 KB Output is correct
66 Correct 0 ms 212 KB Output is correct
67 Correct 0 ms 212 KB Output is correct
68 Correct 0 ms 212 KB Output is correct
69 Correct 1 ms 212 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 54 ms 3984 KB Output is correct
72 Correct 34 ms 3516 KB Output is correct
73 Correct 45 ms 3208 KB Output is correct
74 Correct 25 ms 2760 KB Output is correct
75 Correct 27 ms 2708 KB Output is correct
76 Correct 73 ms 4304 KB Output is correct
77 Correct 81 ms 3104 KB Output is correct
78 Correct 72 ms 3496 KB Output is correct
79 Correct 64 ms 3280 KB Output is correct
80 Correct 0 ms 212 KB Output is correct
81 Correct 0 ms 212 KB Output is correct
82 Correct 1 ms 340 KB Output is correct
83 Correct 7 ms 724 KB Output is correct
84 Correct 8 ms 852 KB Output is correct
85 Correct 2 ms 468 KB Output is correct
86 Correct 0 ms 212 KB Output is correct
87 Correct 9 ms 944 KB Output is correct
88 Correct 0 ms 212 KB Output is correct
89 Correct 1 ms 212 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 4 ms 852 KB Output is correct
92 Correct 17 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 340 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 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 0 ms 340 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 1 ms 372 KB Output is correct
66 Correct 0 ms 212 KB Output is correct
67 Correct 0 ms 212 KB Output is correct
68 Correct 0 ms 212 KB Output is correct
69 Correct 1 ms 212 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 54 ms 3984 KB Output is correct
72 Correct 34 ms 3516 KB Output is correct
73 Correct 45 ms 3208 KB Output is correct
74 Correct 25 ms 2760 KB Output is correct
75 Correct 27 ms 2708 KB Output is correct
76 Correct 73 ms 4304 KB Output is correct
77 Correct 81 ms 3104 KB Output is correct
78 Correct 72 ms 3496 KB Output is correct
79 Correct 64 ms 3280 KB Output is correct
80 Correct 0 ms 212 KB Output is correct
81 Correct 0 ms 212 KB Output is correct
82 Correct 1 ms 340 KB Output is correct
83 Correct 7 ms 724 KB Output is correct
84 Correct 8 ms 852 KB Output is correct
85 Correct 2 ms 468 KB Output is correct
86 Correct 0 ms 212 KB Output is correct
87 Correct 9 ms 944 KB Output is correct
88 Correct 0 ms 212 KB Output is correct
89 Correct 1 ms 212 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 4 ms 852 KB Output is correct
92 Correct 17 ms 2392 KB Output is correct
93 Correct 258 ms 11780 KB Output is correct
94 Correct 133 ms 10432 KB Output is correct
95 Correct 196 ms 9420 KB Output is correct
96 Correct 140 ms 8652 KB Output is correct
97 Correct 130 ms 7148 KB Output is correct
98 Correct 362 ms 11632 KB Output is correct
99 Correct 383 ms 11384 KB Output is correct
100 Correct 318 ms 11360 KB Output is correct
101 Correct 436 ms 8528 KB Output is correct
102 Correct 312 ms 7840 KB Output is correct
103 Correct 188 ms 9028 KB Output is correct
104 Correct 1 ms 212 KB Output is correct
105 Correct 1 ms 212 KB Output is correct
106 Correct 2 ms 340 KB Output is correct
107 Correct 36 ms 1304 KB Output is correct
108 Correct 60 ms 2380 KB Output is correct
109 Correct 4 ms 668 KB Output is correct
110 Correct 1 ms 212 KB Output is correct
111 Correct 22 ms 1600 KB Output is correct
112 Correct 1 ms 212 KB Output is correct
113 Correct 0 ms 212 KB Output is correct
114 Correct 2 ms 596 KB Output is correct
115 Correct 0 ms 212 KB Output is correct
116 Correct 3 ms 596 KB Output is correct
117 Correct 61 ms 6656 KB Output is correct