답안 #536883

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
536883 2022-03-14T06:45:07 Z squiddy Toys (CEOI18_toy) C++14
79 / 100
4768 ms 262144 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;
set<int> answers;

void create_tree(int curr, int l_idx, int curr_idx) {
    if (adj_list.size() <= curr_idx) adj_list.resize(curr_idx + 1);
    if (curr == n) return;
    FOR(i, l_idx, factors.size()) {
        int factor = factors[i];
        int new_factor = curr * factor;
        if (curr > n / factor) return;
        if (n % new_factor == 0 && (n / new_factor >= factor || n == new_factor)) {
            int nidx = adj_list.size() + 1;
            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()) {
        if (curr != 1) 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) {
    if (c_total == n) {
        answers.insert(c_sum);
        return;
    }
    for(ii node : adj_list[nd]) {
        dfs(node.se, c_sum + node.fi - 1, c_total * node.fi);
    }
}

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());
    create_tree(1, 0, 0);
    dfs(0, 0, 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:25:25: warning: comparison of integer expressions of different signedness: 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |     if (adj_list.size() <= curr_idx) adj_list.resize(curr_idx + 1);
      |         ~~~~~~~~~~~~~~~~^~~~~~~~~~~
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++)
......
   27 |     FOR(i, l_idx, factors.size()) {
      |         ~~~~~~~~~~~~~~~~~~~~~~~~        
toy.cpp:27:5: note: in expansion of macro 'FOR'
   27 |     FOR(i, l_idx, factors.size()) {
      |     ^~~
toy.cpp: In function 'void dp_factors(int, int)':
toy.cpp:40: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]
   40 |     if (idx == pfac.size()) {
      |         ~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 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 0 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 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 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 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 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 0 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 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 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 0 ms 212 KB Output is correct
24 Correct 0 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 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 468 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 1 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 0 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 340 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 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 0 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 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 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 0 ms 212 KB Output is correct
24 Correct 0 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 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 468 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 1 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 0 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 340 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 2 ms 596 KB Output is correct
51 Correct 2 ms 596 KB Output is correct
52 Correct 2 ms 828 KB Output is correct
53 Correct 2 ms 596 KB Output is correct
54 Correct 1 ms 468 KB Output is correct
55 Correct 3 ms 828 KB Output is correct
56 Correct 2 ms 828 KB Output is correct
57 Correct 3 ms 828 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 1 ms 596 KB Output is correct
62 Correct 1 ms 468 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 1 ms 596 KB Output is correct
66 Correct 1 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 340 KB Output is correct
70 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 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 0 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 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 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 0 ms 212 KB Output is correct
24 Correct 0 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 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 468 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 1 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 0 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 340 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 2 ms 596 KB Output is correct
51 Correct 2 ms 596 KB Output is correct
52 Correct 2 ms 828 KB Output is correct
53 Correct 2 ms 596 KB Output is correct
54 Correct 1 ms 468 KB Output is correct
55 Correct 3 ms 828 KB Output is correct
56 Correct 2 ms 828 KB Output is correct
57 Correct 3 ms 828 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 1 ms 596 KB Output is correct
62 Correct 1 ms 468 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 1 ms 596 KB Output is correct
66 Correct 1 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 340 KB Output is correct
70 Correct 1 ms 468 KB Output is correct
71 Correct 494 ms 60576 KB Output is correct
72 Correct 303 ms 30292 KB Output is correct
73 Correct 490 ms 60344 KB Output is correct
74 Correct 217 ms 18212 KB Output is correct
75 Correct 267 ms 30304 KB Output is correct
76 Correct 979 ms 120464 KB Output is correct
77 Correct 916 ms 120452 KB Output is correct
78 Correct 671 ms 63728 KB Output is correct
79 Correct 722 ms 66668 KB Output is correct
80 Correct 0 ms 212 KB Output is correct
81 Correct 1 ms 212 KB Output is correct
82 Correct 2 ms 828 KB Output is correct
83 Correct 34 ms 8680 KB Output is correct
84 Correct 47 ms 8580 KB Output is correct
85 Correct 6 ms 2164 KB Output is correct
86 Correct 1 ms 340 KB Output is correct
87 Correct 46 ms 7976 KB Output is correct
88 Correct 0 ms 212 KB Output is correct
89 Correct 0 ms 212 KB Output is correct
90 Correct 1 ms 340 KB Output is correct
91 Correct 11 ms 2164 KB Output is correct
92 Correct 82 ms 7764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 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 0 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 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 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 0 ms 212 KB Output is correct
24 Correct 0 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 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 468 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 1 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 0 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 340 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 2 ms 596 KB Output is correct
51 Correct 2 ms 596 KB Output is correct
52 Correct 2 ms 828 KB Output is correct
53 Correct 2 ms 596 KB Output is correct
54 Correct 1 ms 468 KB Output is correct
55 Correct 3 ms 828 KB Output is correct
56 Correct 2 ms 828 KB Output is correct
57 Correct 3 ms 828 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 1 ms 596 KB Output is correct
62 Correct 1 ms 468 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 1 ms 596 KB Output is correct
66 Correct 1 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 340 KB Output is correct
70 Correct 1 ms 468 KB Output is correct
71 Correct 494 ms 60576 KB Output is correct
72 Correct 303 ms 30292 KB Output is correct
73 Correct 490 ms 60344 KB Output is correct
74 Correct 217 ms 18212 KB Output is correct
75 Correct 267 ms 30304 KB Output is correct
76 Correct 979 ms 120464 KB Output is correct
77 Correct 916 ms 120452 KB Output is correct
78 Correct 671 ms 63728 KB Output is correct
79 Correct 722 ms 66668 KB Output is correct
80 Correct 0 ms 212 KB Output is correct
81 Correct 1 ms 212 KB Output is correct
82 Correct 2 ms 828 KB Output is correct
83 Correct 34 ms 8680 KB Output is correct
84 Correct 47 ms 8580 KB Output is correct
85 Correct 6 ms 2164 KB Output is correct
86 Correct 1 ms 340 KB Output is correct
87 Correct 46 ms 7976 KB Output is correct
88 Correct 0 ms 212 KB Output is correct
89 Correct 0 ms 212 KB Output is correct
90 Correct 1 ms 340 KB Output is correct
91 Correct 11 ms 2164 KB Output is correct
92 Correct 82 ms 7764 KB Output is correct
93 Runtime error 4768 ms 262144 KB Execution killed with signal 9
94 Halted 0 ms 0 KB -