Submission #490975

# Submission time Handle Problem Language Result Execution time Memory
490975 2021-11-30T02:36:38 Z duchung Toys (CEOI18_toy) C++17
79 / 100
5000 ms 80608 KB
#include<bits/stdc++.h>
using namespace std;

const int N = 1e6 + 5;

int n;
map<pair<int , int> , bool> visited;
vector<int> Div[N];
vector<int> ans;

void calc(int x)
{
    if (x > 1e6) return;

    for (int i = 1 ; i * i <= x ; ++i)
    {
        if (x % i == 0)
        {
            if (i != 1) Div[x].push_back(i);
            if (i * i != x && x / i != 1) Div[x].push_back(x / i);
        }
    }
}

void build()
{
    for (int i = 1 ; i * i <= n ; ++i)
    {
        if (n % i == 0)
        {
            calc(i);
            if (i * i != n) calc(n / i);
        }
    }
}

void backtrack(int n , int sum)
{
    if (visited[{n , sum}] == true) return;
    visited[{n , sum}] = true;

    if (n == 1) return;

    if (n <= 1e6)
    {
        for (int x : Div[n]) backtrack(n / x , sum + x - 1);
    }
    else
    {
        for (int i = 1 ; i * i <= n ; ++i)
        {
            if (n % i == 0)
            {
                if (i != 1) backtrack(n / i , sum + i - 1);
                if (i * i != n && n / i != 1) backtrack(i , sum + n / i - 1);
            }
        }
    }
}

int main()
{
    // freopen(".inp","r",stdin);
    // freopen(".out","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    build();
    backtrack(n , 0);

    for (auto x : visited)
    {
        if (x.first.first == 1) ans.push_back(x.first.second);
        else break;
    }

    cout << ans.size() << "\n";
    for (int x : ans) cout << x << " ";
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 14 ms 23756 KB Output is correct
3 Correct 11 ms 23796 KB Output is correct
4 Correct 12 ms 23732 KB Output is correct
5 Correct 12 ms 23788 KB Output is correct
6 Correct 12 ms 23744 KB Output is correct
7 Correct 12 ms 23756 KB Output is correct
8 Correct 12 ms 23696 KB Output is correct
9 Correct 13 ms 23764 KB Output is correct
10 Correct 11 ms 23688 KB Output is correct
11 Correct 12 ms 23756 KB Output is correct
12 Correct 12 ms 23792 KB Output is correct
13 Correct 12 ms 23752 KB Output is correct
14 Correct 11 ms 23740 KB Output is correct
15 Correct 11 ms 23796 KB Output is correct
16 Correct 11 ms 23800 KB Output is correct
17 Correct 12 ms 23800 KB Output is correct
18 Correct 11 ms 23764 KB Output is correct
19 Correct 11 ms 23756 KB Output is correct
20 Correct 14 ms 23756 KB Output is correct
21 Correct 11 ms 23756 KB Output is correct
22 Correct 11 ms 23800 KB Output is correct
23 Correct 11 ms 23684 KB Output is correct
24 Correct 14 ms 23756 KB Output is correct
25 Correct 11 ms 23800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 14 ms 23756 KB Output is correct
3 Correct 11 ms 23796 KB Output is correct
4 Correct 12 ms 23732 KB Output is correct
5 Correct 12 ms 23788 KB Output is correct
6 Correct 12 ms 23744 KB Output is correct
7 Correct 12 ms 23756 KB Output is correct
8 Correct 12 ms 23696 KB Output is correct
9 Correct 13 ms 23764 KB Output is correct
10 Correct 11 ms 23688 KB Output is correct
11 Correct 12 ms 23756 KB Output is correct
12 Correct 12 ms 23792 KB Output is correct
13 Correct 12 ms 23752 KB Output is correct
14 Correct 11 ms 23740 KB Output is correct
15 Correct 11 ms 23796 KB Output is correct
16 Correct 11 ms 23800 KB Output is correct
17 Correct 12 ms 23800 KB Output is correct
18 Correct 11 ms 23764 KB Output is correct
19 Correct 11 ms 23756 KB Output is correct
20 Correct 14 ms 23756 KB Output is correct
21 Correct 11 ms 23756 KB Output is correct
22 Correct 11 ms 23800 KB Output is correct
23 Correct 11 ms 23684 KB Output is correct
24 Correct 14 ms 23756 KB Output is correct
25 Correct 11 ms 23800 KB Output is correct
26 Correct 12 ms 23884 KB Output is correct
27 Correct 12 ms 23764 KB Output is correct
28 Correct 11 ms 23756 KB Output is correct
29 Correct 11 ms 23800 KB Output is correct
30 Correct 12 ms 23800 KB Output is correct
31 Correct 12 ms 23828 KB Output is correct
32 Correct 13 ms 23800 KB Output is correct
33 Correct 16 ms 23784 KB Output is correct
34 Correct 12 ms 23716 KB Output is correct
35 Correct 12 ms 23756 KB Output is correct
36 Correct 12 ms 23756 KB Output is correct
37 Correct 12 ms 23756 KB Output is correct
38 Correct 13 ms 23796 KB Output is correct
39 Correct 11 ms 23684 KB Output is correct
40 Correct 11 ms 23840 KB Output is correct
41 Correct 11 ms 23688 KB Output is correct
42 Correct 11 ms 23756 KB Output is correct
43 Correct 11 ms 23756 KB Output is correct
44 Correct 12 ms 23704 KB Output is correct
45 Correct 12 ms 23720 KB Output is correct
46 Correct 14 ms 23800 KB Output is correct
47 Correct 12 ms 23756 KB Output is correct
48 Correct 11 ms 23784 KB Output is correct
49 Correct 12 ms 23756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 14 ms 23756 KB Output is correct
3 Correct 11 ms 23796 KB Output is correct
4 Correct 12 ms 23732 KB Output is correct
5 Correct 12 ms 23788 KB Output is correct
6 Correct 12 ms 23744 KB Output is correct
7 Correct 12 ms 23756 KB Output is correct
8 Correct 12 ms 23696 KB Output is correct
9 Correct 13 ms 23764 KB Output is correct
10 Correct 11 ms 23688 KB Output is correct
11 Correct 12 ms 23756 KB Output is correct
12 Correct 12 ms 23792 KB Output is correct
13 Correct 12 ms 23752 KB Output is correct
14 Correct 11 ms 23740 KB Output is correct
15 Correct 11 ms 23796 KB Output is correct
16 Correct 11 ms 23800 KB Output is correct
17 Correct 12 ms 23800 KB Output is correct
18 Correct 11 ms 23764 KB Output is correct
19 Correct 11 ms 23756 KB Output is correct
20 Correct 14 ms 23756 KB Output is correct
21 Correct 11 ms 23756 KB Output is correct
22 Correct 11 ms 23800 KB Output is correct
23 Correct 11 ms 23684 KB Output is correct
24 Correct 14 ms 23756 KB Output is correct
25 Correct 11 ms 23800 KB Output is correct
26 Correct 12 ms 23884 KB Output is correct
27 Correct 12 ms 23764 KB Output is correct
28 Correct 11 ms 23756 KB Output is correct
29 Correct 11 ms 23800 KB Output is correct
30 Correct 12 ms 23800 KB Output is correct
31 Correct 12 ms 23828 KB Output is correct
32 Correct 13 ms 23800 KB Output is correct
33 Correct 16 ms 23784 KB Output is correct
34 Correct 12 ms 23716 KB Output is correct
35 Correct 12 ms 23756 KB Output is correct
36 Correct 12 ms 23756 KB Output is correct
37 Correct 12 ms 23756 KB Output is correct
38 Correct 13 ms 23796 KB Output is correct
39 Correct 11 ms 23684 KB Output is correct
40 Correct 11 ms 23840 KB Output is correct
41 Correct 11 ms 23688 KB Output is correct
42 Correct 11 ms 23756 KB Output is correct
43 Correct 11 ms 23756 KB Output is correct
44 Correct 12 ms 23704 KB Output is correct
45 Correct 12 ms 23720 KB Output is correct
46 Correct 14 ms 23800 KB Output is correct
47 Correct 12 ms 23756 KB Output is correct
48 Correct 11 ms 23784 KB Output is correct
49 Correct 12 ms 23756 KB Output is correct
50 Correct 15 ms 24088 KB Output is correct
51 Correct 15 ms 24052 KB Output is correct
52 Correct 15 ms 24164 KB Output is correct
53 Correct 19 ms 24012 KB Output is correct
54 Correct 15 ms 23884 KB Output is correct
55 Correct 17 ms 24320 KB Output is correct
56 Correct 20 ms 24176 KB Output is correct
57 Correct 17 ms 24252 KB Output is correct
58 Correct 12 ms 23720 KB Output is correct
59 Correct 12 ms 23756 KB Output is correct
60 Correct 12 ms 23756 KB Output is correct
61 Correct 17 ms 23980 KB Output is correct
62 Correct 13 ms 23856 KB Output is correct
63 Correct 12 ms 23884 KB Output is correct
64 Correct 12 ms 23756 KB Output is correct
65 Correct 14 ms 24012 KB Output is correct
66 Correct 12 ms 23756 KB Output is correct
67 Correct 12 ms 23756 KB Output is correct
68 Correct 17 ms 23688 KB Output is correct
69 Correct 15 ms 23756 KB Output is correct
70 Correct 13 ms 23920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 14 ms 23756 KB Output is correct
3 Correct 11 ms 23796 KB Output is correct
4 Correct 12 ms 23732 KB Output is correct
5 Correct 12 ms 23788 KB Output is correct
6 Correct 12 ms 23744 KB Output is correct
7 Correct 12 ms 23756 KB Output is correct
8 Correct 12 ms 23696 KB Output is correct
9 Correct 13 ms 23764 KB Output is correct
10 Correct 11 ms 23688 KB Output is correct
11 Correct 12 ms 23756 KB Output is correct
12 Correct 12 ms 23792 KB Output is correct
13 Correct 12 ms 23752 KB Output is correct
14 Correct 11 ms 23740 KB Output is correct
15 Correct 11 ms 23796 KB Output is correct
16 Correct 11 ms 23800 KB Output is correct
17 Correct 12 ms 23800 KB Output is correct
18 Correct 11 ms 23764 KB Output is correct
19 Correct 11 ms 23756 KB Output is correct
20 Correct 14 ms 23756 KB Output is correct
21 Correct 11 ms 23756 KB Output is correct
22 Correct 11 ms 23800 KB Output is correct
23 Correct 11 ms 23684 KB Output is correct
24 Correct 14 ms 23756 KB Output is correct
25 Correct 11 ms 23800 KB Output is correct
26 Correct 12 ms 23884 KB Output is correct
27 Correct 12 ms 23764 KB Output is correct
28 Correct 11 ms 23756 KB Output is correct
29 Correct 11 ms 23800 KB Output is correct
30 Correct 12 ms 23800 KB Output is correct
31 Correct 12 ms 23828 KB Output is correct
32 Correct 13 ms 23800 KB Output is correct
33 Correct 16 ms 23784 KB Output is correct
34 Correct 12 ms 23716 KB Output is correct
35 Correct 12 ms 23756 KB Output is correct
36 Correct 12 ms 23756 KB Output is correct
37 Correct 12 ms 23756 KB Output is correct
38 Correct 13 ms 23796 KB Output is correct
39 Correct 11 ms 23684 KB Output is correct
40 Correct 11 ms 23840 KB Output is correct
41 Correct 11 ms 23688 KB Output is correct
42 Correct 11 ms 23756 KB Output is correct
43 Correct 11 ms 23756 KB Output is correct
44 Correct 12 ms 23704 KB Output is correct
45 Correct 12 ms 23720 KB Output is correct
46 Correct 14 ms 23800 KB Output is correct
47 Correct 12 ms 23756 KB Output is correct
48 Correct 11 ms 23784 KB Output is correct
49 Correct 12 ms 23756 KB Output is correct
50 Correct 15 ms 24088 KB Output is correct
51 Correct 15 ms 24052 KB Output is correct
52 Correct 15 ms 24164 KB Output is correct
53 Correct 19 ms 24012 KB Output is correct
54 Correct 15 ms 23884 KB Output is correct
55 Correct 17 ms 24320 KB Output is correct
56 Correct 20 ms 24176 KB Output is correct
57 Correct 17 ms 24252 KB Output is correct
58 Correct 12 ms 23720 KB Output is correct
59 Correct 12 ms 23756 KB Output is correct
60 Correct 12 ms 23756 KB Output is correct
61 Correct 17 ms 23980 KB Output is correct
62 Correct 13 ms 23856 KB Output is correct
63 Correct 12 ms 23884 KB Output is correct
64 Correct 12 ms 23756 KB Output is correct
65 Correct 14 ms 24012 KB Output is correct
66 Correct 12 ms 23756 KB Output is correct
67 Correct 12 ms 23756 KB Output is correct
68 Correct 17 ms 23688 KB Output is correct
69 Correct 15 ms 23756 KB Output is correct
70 Correct 13 ms 23920 KB Output is correct
71 Correct 1287 ms 48352 KB Output is correct
72 Correct 856 ms 42380 KB Output is correct
73 Correct 1192 ms 45688 KB Output is correct
74 Correct 585 ms 38264 KB Output is correct
75 Correct 758 ms 39292 KB Output is correct
76 Correct 2538 ms 56784 KB Output is correct
77 Correct 2269 ms 52960 KB Output is correct
78 Correct 1930 ms 51124 KB Output is correct
79 Correct 1721 ms 50528 KB Output is correct
80 Correct 13 ms 23756 KB Output is correct
81 Correct 12 ms 23756 KB Output is correct
82 Correct 17 ms 24268 KB Output is correct
83 Correct 117 ms 28220 KB Output is correct
84 Correct 142 ms 29232 KB Output is correct
85 Correct 35 ms 25412 KB Output is correct
86 Correct 13 ms 23756 KB Output is correct
87 Correct 168 ms 30080 KB Output is correct
88 Correct 13 ms 23744 KB Output is correct
89 Correct 13 ms 23772 KB Output is correct
90 Correct 14 ms 23756 KB Output is correct
91 Correct 48 ms 26220 KB Output is correct
92 Correct 211 ms 32208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 14 ms 23756 KB Output is correct
3 Correct 11 ms 23796 KB Output is correct
4 Correct 12 ms 23732 KB Output is correct
5 Correct 12 ms 23788 KB Output is correct
6 Correct 12 ms 23744 KB Output is correct
7 Correct 12 ms 23756 KB Output is correct
8 Correct 12 ms 23696 KB Output is correct
9 Correct 13 ms 23764 KB Output is correct
10 Correct 11 ms 23688 KB Output is correct
11 Correct 12 ms 23756 KB Output is correct
12 Correct 12 ms 23792 KB Output is correct
13 Correct 12 ms 23752 KB Output is correct
14 Correct 11 ms 23740 KB Output is correct
15 Correct 11 ms 23796 KB Output is correct
16 Correct 11 ms 23800 KB Output is correct
17 Correct 12 ms 23800 KB Output is correct
18 Correct 11 ms 23764 KB Output is correct
19 Correct 11 ms 23756 KB Output is correct
20 Correct 14 ms 23756 KB Output is correct
21 Correct 11 ms 23756 KB Output is correct
22 Correct 11 ms 23800 KB Output is correct
23 Correct 11 ms 23684 KB Output is correct
24 Correct 14 ms 23756 KB Output is correct
25 Correct 11 ms 23800 KB Output is correct
26 Correct 12 ms 23884 KB Output is correct
27 Correct 12 ms 23764 KB Output is correct
28 Correct 11 ms 23756 KB Output is correct
29 Correct 11 ms 23800 KB Output is correct
30 Correct 12 ms 23800 KB Output is correct
31 Correct 12 ms 23828 KB Output is correct
32 Correct 13 ms 23800 KB Output is correct
33 Correct 16 ms 23784 KB Output is correct
34 Correct 12 ms 23716 KB Output is correct
35 Correct 12 ms 23756 KB Output is correct
36 Correct 12 ms 23756 KB Output is correct
37 Correct 12 ms 23756 KB Output is correct
38 Correct 13 ms 23796 KB Output is correct
39 Correct 11 ms 23684 KB Output is correct
40 Correct 11 ms 23840 KB Output is correct
41 Correct 11 ms 23688 KB Output is correct
42 Correct 11 ms 23756 KB Output is correct
43 Correct 11 ms 23756 KB Output is correct
44 Correct 12 ms 23704 KB Output is correct
45 Correct 12 ms 23720 KB Output is correct
46 Correct 14 ms 23800 KB Output is correct
47 Correct 12 ms 23756 KB Output is correct
48 Correct 11 ms 23784 KB Output is correct
49 Correct 12 ms 23756 KB Output is correct
50 Correct 15 ms 24088 KB Output is correct
51 Correct 15 ms 24052 KB Output is correct
52 Correct 15 ms 24164 KB Output is correct
53 Correct 19 ms 24012 KB Output is correct
54 Correct 15 ms 23884 KB Output is correct
55 Correct 17 ms 24320 KB Output is correct
56 Correct 20 ms 24176 KB Output is correct
57 Correct 17 ms 24252 KB Output is correct
58 Correct 12 ms 23720 KB Output is correct
59 Correct 12 ms 23756 KB Output is correct
60 Correct 12 ms 23756 KB Output is correct
61 Correct 17 ms 23980 KB Output is correct
62 Correct 13 ms 23856 KB Output is correct
63 Correct 12 ms 23884 KB Output is correct
64 Correct 12 ms 23756 KB Output is correct
65 Correct 14 ms 24012 KB Output is correct
66 Correct 12 ms 23756 KB Output is correct
67 Correct 12 ms 23756 KB Output is correct
68 Correct 17 ms 23688 KB Output is correct
69 Correct 15 ms 23756 KB Output is correct
70 Correct 13 ms 23920 KB Output is correct
71 Correct 1287 ms 48352 KB Output is correct
72 Correct 856 ms 42380 KB Output is correct
73 Correct 1192 ms 45688 KB Output is correct
74 Correct 585 ms 38264 KB Output is correct
75 Correct 758 ms 39292 KB Output is correct
76 Correct 2538 ms 56784 KB Output is correct
77 Correct 2269 ms 52960 KB Output is correct
78 Correct 1930 ms 51124 KB Output is correct
79 Correct 1721 ms 50528 KB Output is correct
80 Correct 13 ms 23756 KB Output is correct
81 Correct 12 ms 23756 KB Output is correct
82 Correct 17 ms 24268 KB Output is correct
83 Correct 117 ms 28220 KB Output is correct
84 Correct 142 ms 29232 KB Output is correct
85 Correct 35 ms 25412 KB Output is correct
86 Correct 13 ms 23756 KB Output is correct
87 Correct 168 ms 30080 KB Output is correct
88 Correct 13 ms 23744 KB Output is correct
89 Correct 13 ms 23772 KB Output is correct
90 Correct 14 ms 23756 KB Output is correct
91 Correct 48 ms 26220 KB Output is correct
92 Correct 211 ms 32208 KB Output is correct
93 Execution timed out 5056 ms 80608 KB Time limit exceeded
94 Halted 0 ms 0 KB -