Submission #826048

# Submission time Handle Problem Language Result Execution time Memory
826048 2023-08-15T10:04:28 Z faruk Toys (CEOI18_toy) C++17
59 / 100
5000 ms 6472 KB
#include <bits/stdc++.h>
#define mp make_pair
#define all(a) a.begin(), a.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int maxn = 1e6 + 2;
vector<int> min_prim(maxn);

void sito() {
    for (ll i = 2; i < maxn; i++) {
        if (min_prim[i] != 0)
            continue;
        for (ll j = i ; j < maxn; j += i)
            if (min_prim[j] == 0)  
                min_prim[j] = i;
    }
}

vector<int> facs;
void get_small_primes(int a) {
    if (a == 1)
        return;
    facs.push_back(min_prim[a]);
    get_small_primes(a / min_prim[a]);
}

vector<int> get_small_factors(int a) {
    facs = vector<int>();
    get_small_primes(a);
    vector<int> factors;
    factors.push_back(1);
    vector<int> temp;
    facs.push_back(1e9); int cnt = 0;
    for (int i = 0; i < facs.size() - 1; i++) {
        cnt++;
        if (facs[i] != facs[i + 1]) {
            int val = 1;
            for (int j = 0; j < cnt; j++) {
                val *= facs[i];
                for (int a : factors)
                    temp.push_back(a * val);
            }
            factors.insert(factors.end(), all(temp));
            temp.clear();
            cnt = 0;
        }
    }
    sort(all(factors));
    return factors;
}

vector<int> get_big_factors(int a) {
    vector<int> factors;
    for (int i = 1; i * i <= a; i++) {
        if (i * i == a)
            factors.push_back(a);
        else
        {
            factors.push_back(i);
            factors.push_back(a/i);
        }
    }
    sort(all(factors));
    return factors;
}

set<int> ans;
void recur(int n, int csum) {
    if (n == 1)
    {
        ans.insert(csum);
        return;
    }
    vector<int> factors;
    if (n < maxn)
        factors = get_small_factors(n);
    else
        factors = get_big_factors(n);
    for (int a : factors) { // the actual factor is n/a
        if (a == n)
            return;
        recur(a, csum + n/a - 1);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    sito();
    int n;
    cin >> n;
    recur(n, 0);

    cout << ans.size() << "\n";
    for (int a : ans)
        cout << a <<" ";
    cout <<"\n";
}

Compilation message

toy.cpp: In function 'std::vector<int> get_small_factors(int)':
toy.cpp:38:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for (int i = 0; i < facs.size() - 1; i++) {
      |                     ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4180 KB Output is correct
2 Correct 9 ms 4180 KB Output is correct
3 Correct 6 ms 4180 KB Output is correct
4 Correct 8 ms 4240 KB Output is correct
5 Correct 7 ms 4180 KB Output is correct
6 Correct 9 ms 4180 KB Output is correct
7 Correct 7 ms 4180 KB Output is correct
8 Correct 7 ms 4180 KB Output is correct
9 Correct 9 ms 4244 KB Output is correct
10 Correct 7 ms 4248 KB Output is correct
11 Correct 9 ms 4180 KB Output is correct
12 Correct 9 ms 4180 KB Output is correct
13 Correct 7 ms 4252 KB Output is correct
14 Correct 9 ms 4244 KB Output is correct
15 Correct 6 ms 4244 KB Output is correct
16 Correct 6 ms 4180 KB Output is correct
17 Correct 9 ms 4180 KB Output is correct
18 Correct 6 ms 4180 KB Output is correct
19 Correct 6 ms 4180 KB Output is correct
20 Correct 7 ms 4180 KB Output is correct
21 Correct 9 ms 4252 KB Output is correct
22 Correct 7 ms 4184 KB Output is correct
23 Correct 8 ms 4236 KB Output is correct
24 Correct 7 ms 4180 KB Output is correct
25 Correct 8 ms 4180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4180 KB Output is correct
2 Correct 9 ms 4180 KB Output is correct
3 Correct 6 ms 4180 KB Output is correct
4 Correct 8 ms 4240 KB Output is correct
5 Correct 7 ms 4180 KB Output is correct
6 Correct 9 ms 4180 KB Output is correct
7 Correct 7 ms 4180 KB Output is correct
8 Correct 7 ms 4180 KB Output is correct
9 Correct 9 ms 4244 KB Output is correct
10 Correct 7 ms 4248 KB Output is correct
11 Correct 9 ms 4180 KB Output is correct
12 Correct 9 ms 4180 KB Output is correct
13 Correct 7 ms 4252 KB Output is correct
14 Correct 9 ms 4244 KB Output is correct
15 Correct 6 ms 4244 KB Output is correct
16 Correct 6 ms 4180 KB Output is correct
17 Correct 9 ms 4180 KB Output is correct
18 Correct 6 ms 4180 KB Output is correct
19 Correct 6 ms 4180 KB Output is correct
20 Correct 7 ms 4180 KB Output is correct
21 Correct 9 ms 4252 KB Output is correct
22 Correct 7 ms 4184 KB Output is correct
23 Correct 8 ms 4236 KB Output is correct
24 Correct 7 ms 4180 KB Output is correct
25 Correct 8 ms 4180 KB Output is correct
26 Correct 13 ms 4180 KB Output is correct
27 Correct 13 ms 4244 KB Output is correct
28 Correct 8 ms 4180 KB Output is correct
29 Correct 7 ms 4180 KB Output is correct
30 Correct 10 ms 4244 KB Output is correct
31 Correct 23 ms 4180 KB Output is correct
32 Correct 19 ms 4244 KB Output is correct
33 Correct 12 ms 4248 KB Output is correct
34 Correct 6 ms 4244 KB Output is correct
35 Correct 7 ms 4180 KB Output is correct
36 Correct 9 ms 4180 KB Output is correct
37 Correct 12 ms 4180 KB Output is correct
38 Correct 7 ms 4180 KB Output is correct
39 Correct 8 ms 4180 KB Output is correct
40 Correct 11 ms 4180 KB Output is correct
41 Correct 7 ms 4180 KB Output is correct
42 Correct 10 ms 4240 KB Output is correct
43 Correct 7 ms 4248 KB Output is correct
44 Correct 6 ms 4180 KB Output is correct
45 Correct 7 ms 4180 KB Output is correct
46 Correct 6 ms 4180 KB Output is correct
47 Correct 13 ms 4248 KB Output is correct
48 Correct 9 ms 4180 KB Output is correct
49 Correct 7 ms 4180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4180 KB Output is correct
2 Correct 9 ms 4180 KB Output is correct
3 Correct 6 ms 4180 KB Output is correct
4 Correct 8 ms 4240 KB Output is correct
5 Correct 7 ms 4180 KB Output is correct
6 Correct 9 ms 4180 KB Output is correct
7 Correct 7 ms 4180 KB Output is correct
8 Correct 7 ms 4180 KB Output is correct
9 Correct 9 ms 4244 KB Output is correct
10 Correct 7 ms 4248 KB Output is correct
11 Correct 9 ms 4180 KB Output is correct
12 Correct 9 ms 4180 KB Output is correct
13 Correct 7 ms 4252 KB Output is correct
14 Correct 9 ms 4244 KB Output is correct
15 Correct 6 ms 4244 KB Output is correct
16 Correct 6 ms 4180 KB Output is correct
17 Correct 9 ms 4180 KB Output is correct
18 Correct 6 ms 4180 KB Output is correct
19 Correct 6 ms 4180 KB Output is correct
20 Correct 7 ms 4180 KB Output is correct
21 Correct 9 ms 4252 KB Output is correct
22 Correct 7 ms 4184 KB Output is correct
23 Correct 8 ms 4236 KB Output is correct
24 Correct 7 ms 4180 KB Output is correct
25 Correct 8 ms 4180 KB Output is correct
26 Correct 13 ms 4180 KB Output is correct
27 Correct 13 ms 4244 KB Output is correct
28 Correct 8 ms 4180 KB Output is correct
29 Correct 7 ms 4180 KB Output is correct
30 Correct 10 ms 4244 KB Output is correct
31 Correct 23 ms 4180 KB Output is correct
32 Correct 19 ms 4244 KB Output is correct
33 Correct 12 ms 4248 KB Output is correct
34 Correct 6 ms 4244 KB Output is correct
35 Correct 7 ms 4180 KB Output is correct
36 Correct 9 ms 4180 KB Output is correct
37 Correct 12 ms 4180 KB Output is correct
38 Correct 7 ms 4180 KB Output is correct
39 Correct 8 ms 4180 KB Output is correct
40 Correct 11 ms 4180 KB Output is correct
41 Correct 7 ms 4180 KB Output is correct
42 Correct 10 ms 4240 KB Output is correct
43 Correct 7 ms 4248 KB Output is correct
44 Correct 6 ms 4180 KB Output is correct
45 Correct 7 ms 4180 KB Output is correct
46 Correct 6 ms 4180 KB Output is correct
47 Correct 13 ms 4248 KB Output is correct
48 Correct 9 ms 4180 KB Output is correct
49 Correct 7 ms 4180 KB Output is correct
50 Correct 77 ms 4280 KB Output is correct
51 Correct 59 ms 4260 KB Output is correct
52 Correct 136 ms 4184 KB Output is correct
53 Correct 111 ms 4268 KB Output is correct
54 Correct 21 ms 4180 KB Output is correct
55 Correct 311 ms 4260 KB Output is correct
56 Correct 372 ms 4264 KB Output is correct
57 Correct 145 ms 4180 KB Output is correct
58 Correct 9 ms 4180 KB Output is correct
59 Correct 6 ms 4244 KB Output is correct
60 Correct 20 ms 4180 KB Output is correct
61 Correct 220 ms 4260 KB Output is correct
62 Correct 21 ms 4244 KB Output is correct
63 Correct 17 ms 4248 KB Output is correct
64 Correct 7 ms 4180 KB Output is correct
65 Correct 57 ms 4264 KB Output is correct
66 Correct 10 ms 4180 KB Output is correct
67 Correct 10 ms 4180 KB Output is correct
68 Correct 10 ms 4180 KB Output is correct
69 Correct 11 ms 4252 KB Output is correct
70 Correct 17 ms 4180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4180 KB Output is correct
2 Correct 9 ms 4180 KB Output is correct
3 Correct 6 ms 4180 KB Output is correct
4 Correct 8 ms 4240 KB Output is correct
5 Correct 7 ms 4180 KB Output is correct
6 Correct 9 ms 4180 KB Output is correct
7 Correct 7 ms 4180 KB Output is correct
8 Correct 7 ms 4180 KB Output is correct
9 Correct 9 ms 4244 KB Output is correct
10 Correct 7 ms 4248 KB Output is correct
11 Correct 9 ms 4180 KB Output is correct
12 Correct 9 ms 4180 KB Output is correct
13 Correct 7 ms 4252 KB Output is correct
14 Correct 9 ms 4244 KB Output is correct
15 Correct 6 ms 4244 KB Output is correct
16 Correct 6 ms 4180 KB Output is correct
17 Correct 9 ms 4180 KB Output is correct
18 Correct 6 ms 4180 KB Output is correct
19 Correct 6 ms 4180 KB Output is correct
20 Correct 7 ms 4180 KB Output is correct
21 Correct 9 ms 4252 KB Output is correct
22 Correct 7 ms 4184 KB Output is correct
23 Correct 8 ms 4236 KB Output is correct
24 Correct 7 ms 4180 KB Output is correct
25 Correct 8 ms 4180 KB Output is correct
26 Correct 13 ms 4180 KB Output is correct
27 Correct 13 ms 4244 KB Output is correct
28 Correct 8 ms 4180 KB Output is correct
29 Correct 7 ms 4180 KB Output is correct
30 Correct 10 ms 4244 KB Output is correct
31 Correct 23 ms 4180 KB Output is correct
32 Correct 19 ms 4244 KB Output is correct
33 Correct 12 ms 4248 KB Output is correct
34 Correct 6 ms 4244 KB Output is correct
35 Correct 7 ms 4180 KB Output is correct
36 Correct 9 ms 4180 KB Output is correct
37 Correct 12 ms 4180 KB Output is correct
38 Correct 7 ms 4180 KB Output is correct
39 Correct 8 ms 4180 KB Output is correct
40 Correct 11 ms 4180 KB Output is correct
41 Correct 7 ms 4180 KB Output is correct
42 Correct 10 ms 4240 KB Output is correct
43 Correct 7 ms 4248 KB Output is correct
44 Correct 6 ms 4180 KB Output is correct
45 Correct 7 ms 4180 KB Output is correct
46 Correct 6 ms 4180 KB Output is correct
47 Correct 13 ms 4248 KB Output is correct
48 Correct 9 ms 4180 KB Output is correct
49 Correct 7 ms 4180 KB Output is correct
50 Correct 77 ms 4280 KB Output is correct
51 Correct 59 ms 4260 KB Output is correct
52 Correct 136 ms 4184 KB Output is correct
53 Correct 111 ms 4268 KB Output is correct
54 Correct 21 ms 4180 KB Output is correct
55 Correct 311 ms 4260 KB Output is correct
56 Correct 372 ms 4264 KB Output is correct
57 Correct 145 ms 4180 KB Output is correct
58 Correct 9 ms 4180 KB Output is correct
59 Correct 6 ms 4244 KB Output is correct
60 Correct 20 ms 4180 KB Output is correct
61 Correct 220 ms 4260 KB Output is correct
62 Correct 21 ms 4244 KB Output is correct
63 Correct 17 ms 4248 KB Output is correct
64 Correct 7 ms 4180 KB Output is correct
65 Correct 57 ms 4264 KB Output is correct
66 Correct 10 ms 4180 KB Output is correct
67 Correct 10 ms 4180 KB Output is correct
68 Correct 10 ms 4180 KB Output is correct
69 Correct 11 ms 4252 KB Output is correct
70 Correct 17 ms 4180 KB Output is correct
71 Execution timed out 5024 ms 6472 KB Time limit exceeded
72 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4180 KB Output is correct
2 Correct 9 ms 4180 KB Output is correct
3 Correct 6 ms 4180 KB Output is correct
4 Correct 8 ms 4240 KB Output is correct
5 Correct 7 ms 4180 KB Output is correct
6 Correct 9 ms 4180 KB Output is correct
7 Correct 7 ms 4180 KB Output is correct
8 Correct 7 ms 4180 KB Output is correct
9 Correct 9 ms 4244 KB Output is correct
10 Correct 7 ms 4248 KB Output is correct
11 Correct 9 ms 4180 KB Output is correct
12 Correct 9 ms 4180 KB Output is correct
13 Correct 7 ms 4252 KB Output is correct
14 Correct 9 ms 4244 KB Output is correct
15 Correct 6 ms 4244 KB Output is correct
16 Correct 6 ms 4180 KB Output is correct
17 Correct 9 ms 4180 KB Output is correct
18 Correct 6 ms 4180 KB Output is correct
19 Correct 6 ms 4180 KB Output is correct
20 Correct 7 ms 4180 KB Output is correct
21 Correct 9 ms 4252 KB Output is correct
22 Correct 7 ms 4184 KB Output is correct
23 Correct 8 ms 4236 KB Output is correct
24 Correct 7 ms 4180 KB Output is correct
25 Correct 8 ms 4180 KB Output is correct
26 Correct 13 ms 4180 KB Output is correct
27 Correct 13 ms 4244 KB Output is correct
28 Correct 8 ms 4180 KB Output is correct
29 Correct 7 ms 4180 KB Output is correct
30 Correct 10 ms 4244 KB Output is correct
31 Correct 23 ms 4180 KB Output is correct
32 Correct 19 ms 4244 KB Output is correct
33 Correct 12 ms 4248 KB Output is correct
34 Correct 6 ms 4244 KB Output is correct
35 Correct 7 ms 4180 KB Output is correct
36 Correct 9 ms 4180 KB Output is correct
37 Correct 12 ms 4180 KB Output is correct
38 Correct 7 ms 4180 KB Output is correct
39 Correct 8 ms 4180 KB Output is correct
40 Correct 11 ms 4180 KB Output is correct
41 Correct 7 ms 4180 KB Output is correct
42 Correct 10 ms 4240 KB Output is correct
43 Correct 7 ms 4248 KB Output is correct
44 Correct 6 ms 4180 KB Output is correct
45 Correct 7 ms 4180 KB Output is correct
46 Correct 6 ms 4180 KB Output is correct
47 Correct 13 ms 4248 KB Output is correct
48 Correct 9 ms 4180 KB Output is correct
49 Correct 7 ms 4180 KB Output is correct
50 Correct 77 ms 4280 KB Output is correct
51 Correct 59 ms 4260 KB Output is correct
52 Correct 136 ms 4184 KB Output is correct
53 Correct 111 ms 4268 KB Output is correct
54 Correct 21 ms 4180 KB Output is correct
55 Correct 311 ms 4260 KB Output is correct
56 Correct 372 ms 4264 KB Output is correct
57 Correct 145 ms 4180 KB Output is correct
58 Correct 9 ms 4180 KB Output is correct
59 Correct 6 ms 4244 KB Output is correct
60 Correct 20 ms 4180 KB Output is correct
61 Correct 220 ms 4260 KB Output is correct
62 Correct 21 ms 4244 KB Output is correct
63 Correct 17 ms 4248 KB Output is correct
64 Correct 7 ms 4180 KB Output is correct
65 Correct 57 ms 4264 KB Output is correct
66 Correct 10 ms 4180 KB Output is correct
67 Correct 10 ms 4180 KB Output is correct
68 Correct 10 ms 4180 KB Output is correct
69 Correct 11 ms 4252 KB Output is correct
70 Correct 17 ms 4180 KB Output is correct
71 Execution timed out 5024 ms 6472 KB Time limit exceeded
72 Halted 0 ms 0 KB -