Submission #438353

# Submission time Handle Problem Language Result Execution time Memory
438353 2021-06-27T21:17:57 Z definitelynotmee Toys (CEOI18_toy) C++
79 / 100
5000 ms 145272 KB
#include <bits/stdc++.h>
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INFL = (1LL<<62)-1;
const int INF = (1<<30)-1;
const int MOD = 1e9 + 7;
const int MAXN = 1e6+1;

int power(int in, int exp){
    int cur = in;
    int resp = 1;
    for(int i = 0; i < 31; i++){
        if((1<<i)&exp){
            resp*=cur;
        }
        cur*=cur;
    }
    return resp;
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n;
    cin >> n;
    if(n==1){
        cout << 1 << '\n' << 0 << '\n';
        return 0;
    }
    vector<int>fat;
    vector<int>num;
    for(int i = 2; i <= sqrt(n); i++){
        if(n%i == 0){
            fat.push_back(i);
            num.push_back(0);
            while(n%i == 0){
                num[num.size()-1]++;
                n/=i;
            }
        }
    }
    if(n!=0)
        fat.push_back(n),num.push_back(1);

    map<vector<int>,set<pii>> m;
    vector<int> base(fat.size(),0);
    m[base] = {{0,0}};
    function<void(vector<int>)> bt = [&](vector<int>v){
        if(m.find(v)!=m.end())
            return;

        set<pii> resp;
        function<void(int,int)> choice = [&](int id, int cur){
            if(id == v.size()){
                if(cur==1)
                    return;
                bt(v);
                for(pii i : m[v]){
                    resp.insert({i.ff+1,i.ss+cur});
                }
                return;
            }
            int aux = v[id];
            int add = 1;
            while(v[id]>=0){
                choice(id+1,cur*add);
                v[id]--;
                add*=fat[id];
            }
            v[id] = aux;
        };
        choice(0,1);
        m[v] = resp;
    };

    bt(num);
    set<int> trueresp;
    for(pii i : m[num]){
        trueresp.insert(i.ss-i.ff);
    }
    cout << trueresp.size() << '\n';
    for(int i : trueresp)
        cout << i << ' ';
    return 0;

}

Compilation message

toy.cpp: In lambda function:
toy.cpp:62:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |             if(id == v.size()){
      |                ~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 284 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 ms 316 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 284 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 ms 316 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 312 KB Output is correct
31 Correct 2 ms 404 KB Output is correct
32 Correct 3 ms 440 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 2 ms 332 KB Output is correct
38 Correct 2 ms 332 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 2 ms 332 KB Output is correct
41 Correct 1 ms 312 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 1 ms 204 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 284 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 ms 316 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 312 KB Output is correct
31 Correct 2 ms 404 KB Output is correct
32 Correct 3 ms 440 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 2 ms 332 KB Output is correct
38 Correct 2 ms 332 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 2 ms 332 KB Output is correct
41 Correct 1 ms 312 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 1 ms 204 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 6 ms 716 KB Output is correct
51 Correct 5 ms 588 KB Output is correct
52 Correct 7 ms 716 KB Output is correct
53 Correct 5 ms 640 KB Output is correct
54 Correct 3 ms 460 KB Output is correct
55 Correct 9 ms 972 KB Output is correct
56 Correct 10 ms 844 KB Output is correct
57 Correct 7 ms 844 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 2 ms 332 KB Output is correct
61 Correct 9 ms 844 KB Output is correct
62 Correct 4 ms 588 KB Output is correct
63 Correct 3 ms 332 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Correct 7 ms 700 KB Output is correct
66 Correct 1 ms 204 KB Output is correct
67 Correct 1 ms 204 KB Output is correct
68 Correct 1 ms 204 KB Output is correct
69 Correct 1 ms 332 KB Output is correct
70 Correct 2 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 284 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 ms 316 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 312 KB Output is correct
31 Correct 2 ms 404 KB Output is correct
32 Correct 3 ms 440 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 2 ms 332 KB Output is correct
38 Correct 2 ms 332 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 2 ms 332 KB Output is correct
41 Correct 1 ms 312 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 1 ms 204 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 6 ms 716 KB Output is correct
51 Correct 5 ms 588 KB Output is correct
52 Correct 7 ms 716 KB Output is correct
53 Correct 5 ms 640 KB Output is correct
54 Correct 3 ms 460 KB Output is correct
55 Correct 9 ms 972 KB Output is correct
56 Correct 10 ms 844 KB Output is correct
57 Correct 7 ms 844 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 2 ms 332 KB Output is correct
61 Correct 9 ms 844 KB Output is correct
62 Correct 4 ms 588 KB Output is correct
63 Correct 3 ms 332 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Correct 7 ms 700 KB Output is correct
66 Correct 1 ms 204 KB Output is correct
67 Correct 1 ms 204 KB Output is correct
68 Correct 1 ms 204 KB Output is correct
69 Correct 1 ms 332 KB Output is correct
70 Correct 2 ms 440 KB Output is correct
71 Correct 842 ms 33332 KB Output is correct
72 Correct 572 ms 23472 KB Output is correct
73 Correct 847 ms 32088 KB Output is correct
74 Correct 395 ms 18672 KB Output is correct
75 Correct 467 ms 21420 KB Output is correct
76 Correct 1496 ms 51348 KB Output is correct
77 Correct 1554 ms 50184 KB Output is correct
78 Correct 1180 ms 42172 KB Output is correct
79 Correct 1364 ms 43296 KB Output is correct
80 Correct 1 ms 204 KB Output is correct
81 Correct 1 ms 204 KB Output is correct
82 Correct 16 ms 1332 KB Output is correct
83 Correct 399 ms 14396 KB Output is correct
84 Correct 423 ms 14840 KB Output is correct
85 Correct 63 ms 3844 KB Output is correct
86 Correct 2 ms 332 KB Output is correct
87 Correct 440 ms 16660 KB Output is correct
88 Correct 1 ms 312 KB Output is correct
89 Correct 1 ms 308 KB Output is correct
90 Correct 2 ms 332 KB Output is correct
91 Correct 32 ms 2632 KB Output is correct
92 Correct 155 ms 9092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 284 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 ms 316 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 312 KB Output is correct
31 Correct 2 ms 404 KB Output is correct
32 Correct 3 ms 440 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 2 ms 332 KB Output is correct
38 Correct 2 ms 332 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 2 ms 332 KB Output is correct
41 Correct 1 ms 312 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 1 ms 204 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 6 ms 716 KB Output is correct
51 Correct 5 ms 588 KB Output is correct
52 Correct 7 ms 716 KB Output is correct
53 Correct 5 ms 640 KB Output is correct
54 Correct 3 ms 460 KB Output is correct
55 Correct 9 ms 972 KB Output is correct
56 Correct 10 ms 844 KB Output is correct
57 Correct 7 ms 844 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 2 ms 332 KB Output is correct
61 Correct 9 ms 844 KB Output is correct
62 Correct 4 ms 588 KB Output is correct
63 Correct 3 ms 332 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Correct 7 ms 700 KB Output is correct
66 Correct 1 ms 204 KB Output is correct
67 Correct 1 ms 204 KB Output is correct
68 Correct 1 ms 204 KB Output is correct
69 Correct 1 ms 332 KB Output is correct
70 Correct 2 ms 440 KB Output is correct
71 Correct 842 ms 33332 KB Output is correct
72 Correct 572 ms 23472 KB Output is correct
73 Correct 847 ms 32088 KB Output is correct
74 Correct 395 ms 18672 KB Output is correct
75 Correct 467 ms 21420 KB Output is correct
76 Correct 1496 ms 51348 KB Output is correct
77 Correct 1554 ms 50184 KB Output is correct
78 Correct 1180 ms 42172 KB Output is correct
79 Correct 1364 ms 43296 KB Output is correct
80 Correct 1 ms 204 KB Output is correct
81 Correct 1 ms 204 KB Output is correct
82 Correct 16 ms 1332 KB Output is correct
83 Correct 399 ms 14396 KB Output is correct
84 Correct 423 ms 14840 KB Output is correct
85 Correct 63 ms 3844 KB Output is correct
86 Correct 2 ms 332 KB Output is correct
87 Correct 440 ms 16660 KB Output is correct
88 Correct 1 ms 312 KB Output is correct
89 Correct 1 ms 308 KB Output is correct
90 Correct 2 ms 332 KB Output is correct
91 Correct 32 ms 2632 KB Output is correct
92 Correct 155 ms 9092 KB Output is correct
93 Execution timed out 5028 ms 145272 KB Time limit exceeded
94 Halted 0 ms 0 KB -