Submission #1053445

# Submission time Handle Problem Language Result Execution time Memory
1053445 2024-08-11T11:57:25 Z VMaksimoski008 Toys (CEOI18_toy) C++17
79 / 100
5000 ms 124192 KB
#include <bits/stdc++.h>
//#define int long long

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;

map<pii, vector<int> > mp;

vector<int> f(int n, int s) {
    if(n == 1) return { s };
    if(mp.count({ n, s })) return mp[{ n, s }];
    vector<int> ans;

    for(int i=1; i*i<=n; i++) {
        if(n % i == 0 && i > 1) {
            auto res = f(n/i, s+i-1);
            for(int &x : res) ans.push_back(x);
        }

        if(n % i == 0 && i * i != n && n / i > 1) {
            auto res = f(n/(n/i), s+(n/i)-1);
            for(int &x : res) ans.push_back(x);
        }
    }

    sort(ans.begin(), ans.end());
    vector<int> ans2;

    if(ans.size() > 0) {
        ans2.push_back(ans[0]);
        for(int i=1; i<ans.size(); i++) if(ans[i] != ans2.back()) ans2.push_back(ans[i]);
    }

    return mp[{ n, s }] = ans2;
}

signed main() {
    //a b c
    //(a + 1)(b + 1)(c + 1) = n
    //maks log(n) razlicni
    //baska (a + 1), (b + 1), (c + 1) | n

    int n;
    cin >> n;

    vector<int> ans = f(n, 0);

    cout << ans.size() << '\n';
    for(int &x : ans) cout << x << " ";
    return 0;
}

Compilation message

toy.cpp: In function 'std::vector<int> f(int, 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=1; i<ans.size(); i++) if(ans[i] != ans2.back()) ans2.push_back(ans[i]);
      |                      ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 428 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 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 0 ms 344 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 0 ms 432 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 0 ms 348 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 432 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 428 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 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 0 ms 344 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 0 ms 432 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 0 ms 348 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 432 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 2 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 2 ms 604 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 2 ms 344 KB Output is correct
34 Correct 0 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 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 412 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 344 KB Output is correct
46 Correct 0 ms 348 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 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 428 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 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 0 ms 344 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 0 ms 432 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 0 ms 348 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 432 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 2 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 2 ms 604 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 2 ms 344 KB Output is correct
34 Correct 0 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 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 412 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 344 KB Output is correct
46 Correct 0 ms 348 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 9 ms 1116 KB Output is correct
51 Correct 6 ms 920 KB Output is correct
52 Correct 7 ms 892 KB Output is correct
53 Correct 6 ms 860 KB Output is correct
54 Correct 3 ms 604 KB Output is correct
55 Correct 12 ms 1416 KB Output is correct
56 Correct 11 ms 1116 KB Output is correct
57 Correct 12 ms 1020 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 436 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 5 ms 860 KB Output is correct
62 Correct 2 ms 604 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 5 ms 860 KB Output is correct
66 Correct 1 ms 344 KB Output is correct
67 Correct 0 ms 348 KB Output is correct
68 Correct 0 ms 348 KB Output is correct
69 Correct 0 ms 348 KB Output is correct
70 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 428 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 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 0 ms 344 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 0 ms 432 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 0 ms 348 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 432 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 2 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 2 ms 604 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 2 ms 344 KB Output is correct
34 Correct 0 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 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 412 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 344 KB Output is correct
46 Correct 0 ms 348 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 9 ms 1116 KB Output is correct
51 Correct 6 ms 920 KB Output is correct
52 Correct 7 ms 892 KB Output is correct
53 Correct 6 ms 860 KB Output is correct
54 Correct 3 ms 604 KB Output is correct
55 Correct 12 ms 1416 KB Output is correct
56 Correct 11 ms 1116 KB Output is correct
57 Correct 12 ms 1020 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 436 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 5 ms 860 KB Output is correct
62 Correct 2 ms 604 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 5 ms 860 KB Output is correct
66 Correct 1 ms 344 KB Output is correct
67 Correct 0 ms 348 KB Output is correct
68 Correct 0 ms 348 KB Output is correct
69 Correct 0 ms 348 KB Output is correct
70 Correct 2 ms 604 KB Output is correct
71 Correct 2481 ms 65612 KB Output is correct
72 Correct 1337 ms 45972 KB Output is correct
73 Correct 2495 ms 63388 KB Output is correct
74 Correct 1006 ms 35196 KB Output is correct
75 Correct 1346 ms 40676 KB Output is correct
76 Correct 4981 ms 105604 KB Output is correct
77 Correct 4862 ms 101868 KB Output is correct
78 Correct 3394 ms 84384 KB Output is correct
79 Correct 3529 ms 85796 KB Output is correct
80 Correct 1 ms 348 KB Output is correct
81 Correct 0 ms 348 KB Output is correct
82 Correct 11 ms 1372 KB Output is correct
83 Correct 316 ms 13256 KB Output is correct
84 Correct 355 ms 14364 KB Output is correct
85 Correct 49 ms 3904 KB Output is correct
86 Correct 1 ms 348 KB Output is correct
87 Correct 360 ms 16304 KB Output is correct
88 Correct 0 ms 344 KB Output is correct
89 Correct 0 ms 436 KB Output is correct
90 Correct 1 ms 472 KB Output is correct
91 Correct 62 ms 4700 KB Output is correct
92 Correct 315 ms 16988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 428 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 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 0 ms 344 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 0 ms 432 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 0 ms 348 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 432 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 2 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 2 ms 604 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 2 ms 344 KB Output is correct
34 Correct 0 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 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 412 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 344 KB Output is correct
46 Correct 0 ms 348 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 9 ms 1116 KB Output is correct
51 Correct 6 ms 920 KB Output is correct
52 Correct 7 ms 892 KB Output is correct
53 Correct 6 ms 860 KB Output is correct
54 Correct 3 ms 604 KB Output is correct
55 Correct 12 ms 1416 KB Output is correct
56 Correct 11 ms 1116 KB Output is correct
57 Correct 12 ms 1020 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 436 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 5 ms 860 KB Output is correct
62 Correct 2 ms 604 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 5 ms 860 KB Output is correct
66 Correct 1 ms 344 KB Output is correct
67 Correct 0 ms 348 KB Output is correct
68 Correct 0 ms 348 KB Output is correct
69 Correct 0 ms 348 KB Output is correct
70 Correct 2 ms 604 KB Output is correct
71 Correct 2481 ms 65612 KB Output is correct
72 Correct 1337 ms 45972 KB Output is correct
73 Correct 2495 ms 63388 KB Output is correct
74 Correct 1006 ms 35196 KB Output is correct
75 Correct 1346 ms 40676 KB Output is correct
76 Correct 4981 ms 105604 KB Output is correct
77 Correct 4862 ms 101868 KB Output is correct
78 Correct 3394 ms 84384 KB Output is correct
79 Correct 3529 ms 85796 KB Output is correct
80 Correct 1 ms 348 KB Output is correct
81 Correct 0 ms 348 KB Output is correct
82 Correct 11 ms 1372 KB Output is correct
83 Correct 316 ms 13256 KB Output is correct
84 Correct 355 ms 14364 KB Output is correct
85 Correct 49 ms 3904 KB Output is correct
86 Correct 1 ms 348 KB Output is correct
87 Correct 360 ms 16304 KB Output is correct
88 Correct 0 ms 344 KB Output is correct
89 Correct 0 ms 436 KB Output is correct
90 Correct 1 ms 472 KB Output is correct
91 Correct 62 ms 4700 KB Output is correct
92 Correct 315 ms 16988 KB Output is correct
93 Execution timed out 5050 ms 124192 KB Time limit exceeded
94 Halted 0 ms 0 KB -