답안 #1039142

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1039142 2024-07-30T13:38:00 Z Trustfulcomic Toys (CEOI18_toy) C++14
59 / 100
5000 ms 604 KB
#include<bits/stdc++.h>
using namespace std;

set<int> explored;

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;
}

void dfs(set<int>& res, vector<pair<int,int>> pf, int n, int cur){
    if (n == 1){
        res.insert(cur);
        return;
    }
    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 (explored.find(divi) != explored.end()) 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]});
        }
        dfs(res, next_pf, n/divi, cur+divi-1);
        if (cur == 0) explored.insert(divi);
    }

}

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);
    }

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

Compilation message

toy.cpp: In function 'void dfs(std::set<int>&, std::vector<std::pair<int, int> >, int, int)':
toy.cpp:51: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]
   51 |         for (int i = 0; i<pf.size(); i++){
      |                         ~^~~~~~~~~~
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: In function 'int main()':
toy.cpp:70:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |     for (int i = 0; i<primes.size() && cpy_n > 1; i++){
      |                     ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 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 1 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 0 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 0 ms 348 KB Output is correct
19 Correct 0 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 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 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 1 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 0 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 0 ms 348 KB Output is correct
19 Correct 0 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 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 3 ms 600 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 392 KB Output is correct
31 Correct 4 ms 348 KB Output is correct
32 Correct 2 ms 348 KB Output is correct
33 Correct 2 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 2 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 356 KB Output is correct
40 Correct 1 ms 356 KB Output is correct
41 Correct 0 ms 348 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 1 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 388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 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 1 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 0 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 0 ms 348 KB Output is correct
19 Correct 0 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 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 3 ms 600 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 392 KB Output is correct
31 Correct 4 ms 348 KB Output is correct
32 Correct 2 ms 348 KB Output is correct
33 Correct 2 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 2 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 356 KB Output is correct
40 Correct 1 ms 356 KB Output is correct
41 Correct 0 ms 348 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 1 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 388 KB Output is correct
50 Correct 16 ms 348 KB Output is correct
51 Correct 15 ms 604 KB Output is correct
52 Correct 27 ms 468 KB Output is correct
53 Correct 17 ms 348 KB Output is correct
54 Correct 4 ms 348 KB Output is correct
55 Correct 59 ms 472 KB Output is correct
56 Correct 56 ms 452 KB Output is correct
57 Correct 29 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 3 ms 344 KB Output is correct
61 Correct 47 ms 460 KB Output is correct
62 Correct 5 ms 348 KB Output is correct
63 Correct 2 ms 348 KB Output is correct
64 Correct 1 ms 344 KB Output is correct
65 Correct 13 ms 348 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 0 ms 472 KB Output is correct
68 Correct 1 ms 348 KB Output is correct
69 Correct 1 ms 348 KB Output is correct
70 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 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 1 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 0 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 0 ms 348 KB Output is correct
19 Correct 0 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 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 3 ms 600 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 392 KB Output is correct
31 Correct 4 ms 348 KB Output is correct
32 Correct 2 ms 348 KB Output is correct
33 Correct 2 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 2 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 356 KB Output is correct
40 Correct 1 ms 356 KB Output is correct
41 Correct 0 ms 348 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 1 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 388 KB Output is correct
50 Correct 16 ms 348 KB Output is correct
51 Correct 15 ms 604 KB Output is correct
52 Correct 27 ms 468 KB Output is correct
53 Correct 17 ms 348 KB Output is correct
54 Correct 4 ms 348 KB Output is correct
55 Correct 59 ms 472 KB Output is correct
56 Correct 56 ms 452 KB Output is correct
57 Correct 29 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 3 ms 344 KB Output is correct
61 Correct 47 ms 460 KB Output is correct
62 Correct 5 ms 348 KB Output is correct
63 Correct 2 ms 348 KB Output is correct
64 Correct 1 ms 344 KB Output is correct
65 Correct 13 ms 348 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 0 ms 472 KB Output is correct
68 Correct 1 ms 348 KB Output is correct
69 Correct 1 ms 348 KB Output is correct
70 Correct 2 ms 348 KB Output is correct
71 Execution timed out 5070 ms 480 KB Time limit exceeded
72 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 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 1 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 0 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 0 ms 348 KB Output is correct
19 Correct 0 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 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 3 ms 600 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 392 KB Output is correct
31 Correct 4 ms 348 KB Output is correct
32 Correct 2 ms 348 KB Output is correct
33 Correct 2 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 2 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 356 KB Output is correct
40 Correct 1 ms 356 KB Output is correct
41 Correct 0 ms 348 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 1 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 388 KB Output is correct
50 Correct 16 ms 348 KB Output is correct
51 Correct 15 ms 604 KB Output is correct
52 Correct 27 ms 468 KB Output is correct
53 Correct 17 ms 348 KB Output is correct
54 Correct 4 ms 348 KB Output is correct
55 Correct 59 ms 472 KB Output is correct
56 Correct 56 ms 452 KB Output is correct
57 Correct 29 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 3 ms 344 KB Output is correct
61 Correct 47 ms 460 KB Output is correct
62 Correct 5 ms 348 KB Output is correct
63 Correct 2 ms 348 KB Output is correct
64 Correct 1 ms 344 KB Output is correct
65 Correct 13 ms 348 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 0 ms 472 KB Output is correct
68 Correct 1 ms 348 KB Output is correct
69 Correct 1 ms 348 KB Output is correct
70 Correct 2 ms 348 KB Output is correct
71 Execution timed out 5070 ms 480 KB Time limit exceeded
72 Halted 0 ms 0 KB -