Submission #174635

# Submission time Handle Problem Language Result Execution time Memory
174635 2020-01-06T14:01:56 Z gratus907 Toys (CEOI18_toy) C++17
100 / 100
1342 ms 22444 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) ((x).begin()),((x).end())
using pii = pair <int, int>;

int n;
map <int, vector <int>> mp;
bool is_composite[50505];
vector <int> primes;
vector <int> ans;
inline void merge_vectors(vector <int> &a, vector <int> &b)
{
    a.insert(a.end(), b.begin(), b.end());
}
inline void uniquify(vector <int> &v, bool issorted)
{
    if (!issorted)
        sort(all(v));
    v.erase(unique(all(v)),v.end());
}
void prime_sieve()
{
    is_composite[1] = true;
    is_composite[2] = false;
    primes.push_back(2);
    for (int i = 4; i<50000; i+=2) is_composite[i] = true;
    for (int i = 3; i<50000; i+=2)
    {
        if (!is_composite[i])
        {
            primes.push_back(i);
            for (int j = 2*i; j<50000; j+=i)
                is_composite[j] = true;
        }
    }
}

bool check_prime(int x)
{
    if (x == 1) return true;
    if (x < 50000) return !is_composite[x];
    for (auto it:primes)
    {
        if (it>=x) return true;
        if (x%it==0) return false;
    }
    return true;
}
vector <int> start_check(int x)
{
    if (mp.find(x)!=mp.end())
        return mp[x];
    int orx = x;
    vector <int> result;
    vector <int> dvs;
    if (check_prime(x))
        return mp[x] = {x-1};
    for (int i = 2; i*i<=x; i++)
    {
        if (x%i==0)
        {
            dvs.push_back(i);
            dvs.push_back(x/i);
            if(x/i == i)
                dvs.pop_back();
        }
    }
    for (auto it:dvs)
    {
        vector <int> u = start_check(orx/it);
        for (auto it2:u)
            result.push_back(it2+it-1);
    }
    result.push_back(orx-1);
    uniquify(result, false);
    return mp[orx] = result;
}
int32_t main()
{
    cin >> n;
    prime_sieve();
    ans = start_check(n);
    /*for (auto it:mp)
    {
        printf("%d: ",it.first);
        for (auto it2:it.second)
            printf("%d ",it2);
        printf("\n");
    }*/

    printf("%d\n",(int)ans.size());
    for (auto it:ans)
        printf("%d ",it);
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 404 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 3 ms 380 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 380 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 404 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 3 ms 380 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 380 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 3 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 380 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 3 ms 376 KB Output is correct
38 Correct 2 ms 380 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 376 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 3 ms 376 KB Output is correct
48 Correct 3 ms 376 KB Output is correct
49 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 404 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 3 ms 380 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 380 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 3 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 380 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 3 ms 376 KB Output is correct
38 Correct 2 ms 380 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 376 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 3 ms 376 KB Output is correct
48 Correct 3 ms 376 KB Output is correct
49 Correct 3 ms 376 KB Output is correct
50 Correct 4 ms 504 KB Output is correct
51 Correct 4 ms 504 KB Output is correct
52 Correct 4 ms 504 KB Output is correct
53 Correct 4 ms 504 KB Output is correct
54 Correct 3 ms 376 KB Output is correct
55 Correct 5 ms 504 KB Output is correct
56 Correct 5 ms 632 KB Output is correct
57 Correct 5 ms 504 KB Output is correct
58 Correct 2 ms 376 KB Output is correct
59 Correct 2 ms 376 KB Output is correct
60 Correct 2 ms 380 KB Output is correct
61 Correct 3 ms 504 KB Output is correct
62 Correct 3 ms 376 KB Output is correct
63 Correct 3 ms 504 KB Output is correct
64 Correct 2 ms 504 KB Output is correct
65 Correct 3 ms 508 KB Output is correct
66 Correct 2 ms 376 KB Output is correct
67 Correct 2 ms 376 KB Output is correct
68 Correct 2 ms 376 KB Output is correct
69 Correct 3 ms 380 KB Output is correct
70 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 404 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 3 ms 380 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 380 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 3 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 380 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 3 ms 376 KB Output is correct
38 Correct 2 ms 380 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 376 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 3 ms 376 KB Output is correct
48 Correct 3 ms 376 KB Output is correct
49 Correct 3 ms 376 KB Output is correct
50 Correct 4 ms 504 KB Output is correct
51 Correct 4 ms 504 KB Output is correct
52 Correct 4 ms 504 KB Output is correct
53 Correct 4 ms 504 KB Output is correct
54 Correct 3 ms 376 KB Output is correct
55 Correct 5 ms 504 KB Output is correct
56 Correct 5 ms 632 KB Output is correct
57 Correct 5 ms 504 KB Output is correct
58 Correct 2 ms 376 KB Output is correct
59 Correct 2 ms 376 KB Output is correct
60 Correct 2 ms 380 KB Output is correct
61 Correct 3 ms 504 KB Output is correct
62 Correct 3 ms 376 KB Output is correct
63 Correct 3 ms 504 KB Output is correct
64 Correct 2 ms 504 KB Output is correct
65 Correct 3 ms 508 KB Output is correct
66 Correct 2 ms 376 KB Output is correct
67 Correct 2 ms 376 KB Output is correct
68 Correct 2 ms 376 KB Output is correct
69 Correct 3 ms 380 KB Output is correct
70 Correct 3 ms 376 KB Output is correct
71 Correct 205 ms 5168 KB Output is correct
72 Correct 144 ms 4428 KB Output is correct
73 Correct 196 ms 4988 KB Output is correct
74 Correct 111 ms 2968 KB Output is correct
75 Correct 128 ms 3216 KB Output is correct
76 Correct 318 ms 6512 KB Output is correct
77 Correct 292 ms 5944 KB Output is correct
78 Correct 253 ms 5660 KB Output is correct
79 Correct 246 ms 5740 KB Output is correct
80 Correct 2 ms 504 KB Output is correct
81 Correct 2 ms 376 KB Output is correct
82 Correct 4 ms 504 KB Output is correct
83 Correct 30 ms 1100 KB Output is correct
84 Correct 39 ms 1404 KB Output is correct
85 Correct 10 ms 760 KB Output is correct
86 Correct 3 ms 376 KB Output is correct
87 Correct 41 ms 1712 KB Output is correct
88 Correct 2 ms 376 KB Output is correct
89 Correct 2 ms 380 KB Output is correct
90 Correct 3 ms 504 KB Output is correct
91 Correct 14 ms 900 KB Output is correct
92 Correct 52 ms 2004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 404 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 3 ms 380 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 380 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 3 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 380 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 3 ms 376 KB Output is correct
38 Correct 2 ms 380 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 376 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 3 ms 376 KB Output is correct
48 Correct 3 ms 376 KB Output is correct
49 Correct 3 ms 376 KB Output is correct
50 Correct 4 ms 504 KB Output is correct
51 Correct 4 ms 504 KB Output is correct
52 Correct 4 ms 504 KB Output is correct
53 Correct 4 ms 504 KB Output is correct
54 Correct 3 ms 376 KB Output is correct
55 Correct 5 ms 504 KB Output is correct
56 Correct 5 ms 632 KB Output is correct
57 Correct 5 ms 504 KB Output is correct
58 Correct 2 ms 376 KB Output is correct
59 Correct 2 ms 376 KB Output is correct
60 Correct 2 ms 380 KB Output is correct
61 Correct 3 ms 504 KB Output is correct
62 Correct 3 ms 376 KB Output is correct
63 Correct 3 ms 504 KB Output is correct
64 Correct 2 ms 504 KB Output is correct
65 Correct 3 ms 508 KB Output is correct
66 Correct 2 ms 376 KB Output is correct
67 Correct 2 ms 376 KB Output is correct
68 Correct 2 ms 376 KB Output is correct
69 Correct 3 ms 380 KB Output is correct
70 Correct 3 ms 376 KB Output is correct
71 Correct 205 ms 5168 KB Output is correct
72 Correct 144 ms 4428 KB Output is correct
73 Correct 196 ms 4988 KB Output is correct
74 Correct 111 ms 2968 KB Output is correct
75 Correct 128 ms 3216 KB Output is correct
76 Correct 318 ms 6512 KB Output is correct
77 Correct 292 ms 5944 KB Output is correct
78 Correct 253 ms 5660 KB Output is correct
79 Correct 246 ms 5740 KB Output is correct
80 Correct 2 ms 504 KB Output is correct
81 Correct 2 ms 376 KB Output is correct
82 Correct 4 ms 504 KB Output is correct
83 Correct 30 ms 1100 KB Output is correct
84 Correct 39 ms 1404 KB Output is correct
85 Correct 10 ms 760 KB Output is correct
86 Correct 3 ms 376 KB Output is correct
87 Correct 41 ms 1712 KB Output is correct
88 Correct 2 ms 376 KB Output is correct
89 Correct 2 ms 380 KB Output is correct
90 Correct 3 ms 504 KB Output is correct
91 Correct 14 ms 900 KB Output is correct
92 Correct 52 ms 2004 KB Output is correct
93 Correct 1128 ms 20964 KB Output is correct
94 Correct 629 ms 12452 KB Output is correct
95 Correct 726 ms 16560 KB Output is correct
96 Correct 648 ms 12188 KB Output is correct
97 Correct 588 ms 11496 KB Output is correct
98 Correct 1271 ms 21936 KB Output is correct
99 Correct 1342 ms 22240 KB Output is correct
100 Correct 1242 ms 22444 KB Output is correct
101 Correct 1184 ms 21120 KB Output is correct
102 Correct 1039 ms 20460 KB Output is correct
103 Correct 833 ms 19104 KB Output is correct
104 Correct 3 ms 504 KB Output is correct
105 Correct 3 ms 376 KB Output is correct
106 Correct 6 ms 632 KB Output is correct
107 Correct 91 ms 2676 KB Output is correct
108 Correct 228 ms 5164 KB Output is correct
109 Correct 22 ms 976 KB Output is correct
110 Correct 3 ms 380 KB Output is correct
111 Correct 113 ms 3084 KB Output is correct
112 Correct 3 ms 504 KB Output is correct
113 Correct 3 ms 376 KB Output is correct
114 Correct 3 ms 652 KB Output is correct
115 Correct 3 ms 376 KB Output is correct
116 Correct 11 ms 748 KB Output is correct
117 Correct 226 ms 5472 KB Output is correct