Submission #1039168

# Submission time Handle Problem Language Result Execution time Memory
1039168 2024-07-30T14:01:21 Z Trustfulcomic Toys (CEOI18_toy) C++14
100 / 100
1189 ms 16980 KB
#include<bits/stdc++.h>
using namespace std;

set<int> explored;
map<int, vector<int>> mem;

vector<int> primes_to(int n){
    vector<bool> is_prime(n+1, true);
    is_prime[0] = false;
    is_prime[1] = false;

    vector<int> primes;

    for (int i = 0; i<=n; i++){
        if (!is_prime[i]) continue;
        primes.push_back(i);
        for (int j = 2; j*i <= n; j++){
            is_prime[j*i] = false;
        }
    }

    return primes;
}

bool inc_pows(vector<int>& cur, vector<pair<int,int>>& pf){
    for (int i = cur.size()-1; i >= 0; i--){
        if (cur[i] == pf[i].second){
            cur[i] = 0;
        } else {
            cur[i]++;
            return true;
        }
    }
    return false;
}

int int_pow(int x, int e){
    if (e == 0) return 1;
    int r = int_pow(x,e/2);
    if (e%2 == 1) return r*r*x;
    else return r*r;
}

vector<int> dfs(vector<pair<int,int>> pf, int n){
    vector<int> res;
    if (n == 1){
        res = {0};
        return res;
    }

    set<int> bef_res;

    vector<int> cur_pows(pf.size(), 0);
    while(inc_pows(cur_pows, pf)){
        int divi = 1;
        for (int i = 0; i<pf.size(); i++){
            divi *= int_pow(pf[i].first, cur_pows[i]);
        }
        if (mem.count(n/divi)){
            for (int i : mem[n/divi]){
                bef_res.insert(i + divi-1);
            }
            continue;
        }
        vector<pair<int,int>> next_pf;
        for (int i = 0; i<pf.size(); i++){
            next_pf.push_back({pf[i].first, pf[i].second-cur_pows[i]});
        }
        vector<int> cisla =  dfs(next_pf, n/divi);
        for (int i : cisla){
            bef_res.insert(i+divi-1);
        }
        mem[n/divi] = cisla;
    }

    for (int i : bef_res){
        res.push_back(i);
    }
    return res;

}

int main(){
    vector<int> primes = primes_to(sqrt(1000000000)+1);
    int n; cin >> n;
    int cpy_n = n;
    map<int, int> p_factors;
    for (int i = 0; i<primes.size() && cpy_n > 1; i++){
        while (cpy_n % primes[i] == 0){
            p_factors[primes[i]];
            p_factors[primes[i]]++;
            cpy_n /= primes[i];
        }
    }
    if (cpy_n != 1){
        p_factors[cpy_n];
        p_factors[cpy_n]++;
    }

    vector<pair<int,int>> p_fact;
    for (auto pii : p_factors){
        p_fact.push_back(pii);
    }

    vector<int> res;
    res = dfs(p_fact, n);
    cout << res.size() << endl;
    for (int i : res){
        cout << i << " ";
    }
    cout << endl;
}

Compilation message

toy.cpp: In function 'std::vector<int> dfs(std::vector<std::pair<int, int> >, int)':
toy.cpp:56:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         for (int i = 0; i<pf.size(); i++){
      |                         ~^~~~~~~~~~
toy.cpp:66:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         for (int i = 0; i<pf.size(); i++){
      |                         ~^~~~~~~~~~
toy.cpp: In function 'int main()':
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 i = 0; i<primes.size() && cpy_n > 1; i++){
      |                     ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 432 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 432 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 472 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 432 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 472 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 2 ms 348 KB Output is correct
51 Correct 2 ms 508 KB Output is correct
52 Correct 2 ms 468 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 2 ms 348 KB Output is correct
56 Correct 2 ms 348 KB Output is correct
57 Correct 2 ms 348 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 464 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 1 ms 344 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 0 ms 344 KB Output is correct
68 Correct 1 ms 348 KB Output is correct
69 Correct 0 ms 348 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 432 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 472 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 2 ms 348 KB Output is correct
51 Correct 2 ms 508 KB Output is correct
52 Correct 2 ms 468 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 2 ms 348 KB Output is correct
56 Correct 2 ms 348 KB Output is correct
57 Correct 2 ms 348 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 464 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 1 ms 344 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 0 ms 344 KB Output is correct
68 Correct 1 ms 348 KB Output is correct
69 Correct 0 ms 348 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Correct 165 ms 4176 KB Output is correct
72 Correct 117 ms 3412 KB Output is correct
73 Correct 147 ms 3668 KB Output is correct
74 Correct 87 ms 2580 KB Output is correct
75 Correct 98 ms 2848 KB Output is correct
76 Correct 245 ms 5408 KB Output is correct
77 Correct 234 ms 5304 KB Output is correct
78 Correct 188 ms 4644 KB Output is correct
79 Correct 189 ms 4728 KB Output is correct
80 Correct 1 ms 344 KB Output is correct
81 Correct 0 ms 352 KB Output is correct
82 Correct 2 ms 348 KB Output is correct
83 Correct 29 ms 1624 KB Output is correct
84 Correct 39 ms 1368 KB Output is correct
85 Correct 7 ms 860 KB Output is correct
86 Correct 1 ms 468 KB Output is correct
87 Correct 44 ms 1852 KB Output is correct
88 Correct 1 ms 348 KB Output is correct
89 Correct 1 ms 348 KB Output is correct
90 Correct 1 ms 348 KB Output is correct
91 Correct 15 ms 1048 KB Output is correct
92 Correct 63 ms 1712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 432 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 472 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 2 ms 348 KB Output is correct
51 Correct 2 ms 508 KB Output is correct
52 Correct 2 ms 468 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 2 ms 348 KB Output is correct
56 Correct 2 ms 348 KB Output is correct
57 Correct 2 ms 348 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 464 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 1 ms 344 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 0 ms 344 KB Output is correct
68 Correct 1 ms 348 KB Output is correct
69 Correct 0 ms 348 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Correct 165 ms 4176 KB Output is correct
72 Correct 117 ms 3412 KB Output is correct
73 Correct 147 ms 3668 KB Output is correct
74 Correct 87 ms 2580 KB Output is correct
75 Correct 98 ms 2848 KB Output is correct
76 Correct 245 ms 5408 KB Output is correct
77 Correct 234 ms 5304 KB Output is correct
78 Correct 188 ms 4644 KB Output is correct
79 Correct 189 ms 4728 KB Output is correct
80 Correct 1 ms 344 KB Output is correct
81 Correct 0 ms 352 KB Output is correct
82 Correct 2 ms 348 KB Output is correct
83 Correct 29 ms 1624 KB Output is correct
84 Correct 39 ms 1368 KB Output is correct
85 Correct 7 ms 860 KB Output is correct
86 Correct 1 ms 468 KB Output is correct
87 Correct 44 ms 1852 KB Output is correct
88 Correct 1 ms 348 KB Output is correct
89 Correct 1 ms 348 KB Output is correct
90 Correct 1 ms 348 KB Output is correct
91 Correct 15 ms 1048 KB Output is correct
92 Correct 63 ms 1712 KB Output is correct
93 Correct 995 ms 14932 KB Output is correct
94 Correct 557 ms 10132 KB Output is correct
95 Correct 660 ms 10252 KB Output is correct
96 Correct 587 ms 9688 KB Output is correct
97 Correct 549 ms 9400 KB Output is correct
98 Correct 1088 ms 16980 KB Output is correct
99 Correct 1189 ms 16712 KB Output is correct
100 Correct 1026 ms 16504 KB Output is correct
101 Correct 968 ms 15904 KB Output is correct
102 Correct 876 ms 14932 KB Output is correct
103 Correct 727 ms 12880 KB Output is correct
104 Correct 1 ms 472 KB Output is correct
105 Correct 0 ms 348 KB Output is correct
106 Correct 3 ms 724 KB Output is correct
107 Correct 64 ms 3516 KB Output is correct
108 Correct 188 ms 5456 KB Output is correct
109 Correct 18 ms 1372 KB Output is correct
110 Correct 0 ms 464 KB Output is correct
111 Correct 90 ms 3980 KB Output is correct
112 Correct 1 ms 348 KB Output is correct
113 Correct 1 ms 464 KB Output is correct
114 Correct 4 ms 556 KB Output is correct
115 Correct 1 ms 348 KB Output is correct
116 Correct 9 ms 980 KB Output is correct
117 Correct 221 ms 5724 KB Output is correct