Submission #116196

# Submission time Handle Problem Language Result Execution time Memory
116196 2019-06-11T08:44:35 Z JohnTitor Toys (CEOI18_toy) C++11
100 / 100
1534 ms 36688 KB
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=(j); i<=(k); i++)
#define FFOR(i, j, k) for(int i=(j); i<(k); i++)
#define DFOR(i, j, k) for(int i=(j); i>=(k); i--)
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'
#define pb push_back
#define mp make_pair
#define bit(s, i) (((s)>>(i))&1LL)
#define mask(i) ((1LL<<(i)))
#define builtin_popcount __builtin_popcountll
#define __builtin_popcount __builtin_popcountll
using ll=long long; using ld=long double;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const ld pi=acos(0)*2;
template <typename T> inline void read(T &x){char c; bool nega=0; while((!isdigit(c=getchar()))&&(c!='-')); if(c=='-'){nega=1; c=getchar();} x=c-48; while(isdigit(c=getchar())) x=x*10+c-48; if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10); putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){ putchar('-'); x=-x;} writep(x);}
template <typename T> inline void writeln(T x){write(x); putchar('\n');}
#define taskname "Toys"
int n;

vector <pair <int, int>> v;
void factorize(int n){
    int i=2;
    while(i*i<=n){
        if(n%i==0){
            v.pb(mp(i, 0));
            while(n%i==0){
                v.back().second++;
                n/=i;
            }
        }
        i++;
    }
    if(n>1) v.pb(mp(n, 1));
}
vector <int> divisors;
void backtrack(int a, int b, int s){
    if(a==v.size()){
        if(s>1) divisors.pb(s);
    }
    else{
        backtrack(a+1, 0, s);
        if(b<v[a].second) backtrack(a, b+1, s*v[a].first);
    }
}
map <int, vector <pair <int, int>>> f;
void caculate(int u){
    if(!f[u].empty()) return;
    vector <pair <int, bool>> temp;
    temp.pb(mp(u-1, 0));
    temp.pb(mp(u, 1));
    for(int v: divisors) if((u%v==0)&&(u!=v)&&(u/v>=v)){
        caculate(u/v);
        for(auto x: f[u/v]){
            temp.pb(mp(x.first+v-1, 0));
            temp.pb(mp(x.second+v, 1));
        }
    }
    sort(temp.begin(), temp.end());
    int beg=temp[0].first;
    int cnt=0;
    for(auto x: temp){
        if(x.second){
            cnt--;
            if(cnt==0) f[u].pb(mp(beg, x.first-1));
        }
        else{
            cnt++;
            if(cnt==1) beg=x.first;
        }
    }
}
int main(){
    #ifdef Aria
        if(fopen(taskname".in", "r"))
            freopen(taskname".in", "r", stdin);
    #endif // Aria
    read(n);
    factorize(n);
    backtrack(0, 0, 1);
    caculate(n);
    int ans=0;
    for(auto x: f[n]) ans+=x.second-x.first+1;
    writeln(ans);
    for(auto x: f[n]) FOR(i, x.first, x.second) write(i), putchar(' ');
}

Compilation message

toy.cpp: In function 'void backtrack(int, int, int)':
toy.cpp:39:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(a==v.size()){
        ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 256 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 2 ms 256 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 256 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 256 KB Output is correct
39 Correct 2 ms 256 KB Output is correct
40 Correct 3 ms 384 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 2 ms 384 KB Output is correct
43 Correct 2 ms 384 KB Output is correct
44 Correct 2 ms 384 KB Output is correct
45 Correct 2 ms 384 KB Output is correct
46 Correct 2 ms 384 KB Output is correct
47 Correct 2 ms 384 KB Output is correct
48 Correct 2 ms 384 KB Output is correct
49 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 256 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 2 ms 256 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 256 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 256 KB Output is correct
39 Correct 2 ms 256 KB Output is correct
40 Correct 3 ms 384 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 2 ms 384 KB Output is correct
43 Correct 2 ms 384 KB Output is correct
44 Correct 2 ms 384 KB Output is correct
45 Correct 2 ms 384 KB Output is correct
46 Correct 2 ms 384 KB Output is correct
47 Correct 2 ms 384 KB Output is correct
48 Correct 2 ms 384 KB Output is correct
49 Correct 2 ms 384 KB Output is correct
50 Correct 5 ms 512 KB Output is correct
51 Correct 4 ms 384 KB Output is correct
52 Correct 4 ms 512 KB Output is correct
53 Correct 4 ms 384 KB Output is correct
54 Correct 3 ms 384 KB Output is correct
55 Correct 5 ms 512 KB Output is correct
56 Correct 4 ms 512 KB Output is correct
57 Correct 5 ms 384 KB Output is correct
58 Correct 2 ms 256 KB Output is correct
59 Correct 2 ms 384 KB Output is correct
60 Correct 2 ms 256 KB Output is correct
61 Correct 3 ms 384 KB Output is correct
62 Correct 2 ms 384 KB Output is correct
63 Correct 2 ms 384 KB Output is correct
64 Correct 2 ms 384 KB Output is correct
65 Correct 3 ms 384 KB Output is correct
66 Correct 2 ms 384 KB Output is correct
67 Correct 2 ms 256 KB Output is correct
68 Correct 2 ms 384 KB Output is correct
69 Correct 2 ms 384 KB Output is correct
70 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 256 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 2 ms 256 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 256 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 256 KB Output is correct
39 Correct 2 ms 256 KB Output is correct
40 Correct 3 ms 384 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 2 ms 384 KB Output is correct
43 Correct 2 ms 384 KB Output is correct
44 Correct 2 ms 384 KB Output is correct
45 Correct 2 ms 384 KB Output is correct
46 Correct 2 ms 384 KB Output is correct
47 Correct 2 ms 384 KB Output is correct
48 Correct 2 ms 384 KB Output is correct
49 Correct 2 ms 384 KB Output is correct
50 Correct 5 ms 512 KB Output is correct
51 Correct 4 ms 384 KB Output is correct
52 Correct 4 ms 512 KB Output is correct
53 Correct 4 ms 384 KB Output is correct
54 Correct 3 ms 384 KB Output is correct
55 Correct 5 ms 512 KB Output is correct
56 Correct 4 ms 512 KB Output is correct
57 Correct 5 ms 384 KB Output is correct
58 Correct 2 ms 256 KB Output is correct
59 Correct 2 ms 384 KB Output is correct
60 Correct 2 ms 256 KB Output is correct
61 Correct 3 ms 384 KB Output is correct
62 Correct 2 ms 384 KB Output is correct
63 Correct 2 ms 384 KB Output is correct
64 Correct 2 ms 384 KB Output is correct
65 Correct 3 ms 384 KB Output is correct
66 Correct 2 ms 384 KB Output is correct
67 Correct 2 ms 256 KB Output is correct
68 Correct 2 ms 384 KB Output is correct
69 Correct 2 ms 384 KB Output is correct
70 Correct 3 ms 384 KB Output is correct
71 Correct 259 ms 9076 KB Output is correct
72 Correct 199 ms 6332 KB Output is correct
73 Correct 221 ms 6076 KB Output is correct
74 Correct 151 ms 4840 KB Output is correct
75 Correct 159 ms 5600 KB Output is correct
76 Correct 340 ms 9264 KB Output is correct
77 Correct 265 ms 5984 KB Output is correct
78 Correct 270 ms 9052 KB Output is correct
79 Correct 233 ms 5716 KB Output is correct
80 Correct 2 ms 256 KB Output is correct
81 Correct 2 ms 256 KB Output is correct
82 Correct 4 ms 384 KB Output is correct
83 Correct 25 ms 1268 KB Output is correct
84 Correct 55 ms 1924 KB Output is correct
85 Correct 11 ms 840 KB Output is correct
86 Correct 2 ms 384 KB Output is correct
87 Correct 50 ms 1688 KB Output is correct
88 Correct 2 ms 256 KB Output is correct
89 Correct 2 ms 384 KB Output is correct
90 Correct 2 ms 384 KB Output is correct
91 Correct 17 ms 1320 KB Output is correct
92 Correct 87 ms 4616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 256 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 2 ms 256 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 256 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 256 KB Output is correct
39 Correct 2 ms 256 KB Output is correct
40 Correct 3 ms 384 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 2 ms 384 KB Output is correct
43 Correct 2 ms 384 KB Output is correct
44 Correct 2 ms 384 KB Output is correct
45 Correct 2 ms 384 KB Output is correct
46 Correct 2 ms 384 KB Output is correct
47 Correct 2 ms 384 KB Output is correct
48 Correct 2 ms 384 KB Output is correct
49 Correct 2 ms 384 KB Output is correct
50 Correct 5 ms 512 KB Output is correct
51 Correct 4 ms 384 KB Output is correct
52 Correct 4 ms 512 KB Output is correct
53 Correct 4 ms 384 KB Output is correct
54 Correct 3 ms 384 KB Output is correct
55 Correct 5 ms 512 KB Output is correct
56 Correct 4 ms 512 KB Output is correct
57 Correct 5 ms 384 KB Output is correct
58 Correct 2 ms 256 KB Output is correct
59 Correct 2 ms 384 KB Output is correct
60 Correct 2 ms 256 KB Output is correct
61 Correct 3 ms 384 KB Output is correct
62 Correct 2 ms 384 KB Output is correct
63 Correct 2 ms 384 KB Output is correct
64 Correct 2 ms 384 KB Output is correct
65 Correct 3 ms 384 KB Output is correct
66 Correct 2 ms 384 KB Output is correct
67 Correct 2 ms 256 KB Output is correct
68 Correct 2 ms 384 KB Output is correct
69 Correct 2 ms 384 KB Output is correct
70 Correct 3 ms 384 KB Output is correct
71 Correct 259 ms 9076 KB Output is correct
72 Correct 199 ms 6332 KB Output is correct
73 Correct 221 ms 6076 KB Output is correct
74 Correct 151 ms 4840 KB Output is correct
75 Correct 159 ms 5600 KB Output is correct
76 Correct 340 ms 9264 KB Output is correct
77 Correct 265 ms 5984 KB Output is correct
78 Correct 270 ms 9052 KB Output is correct
79 Correct 233 ms 5716 KB Output is correct
80 Correct 2 ms 256 KB Output is correct
81 Correct 2 ms 256 KB Output is correct
82 Correct 4 ms 384 KB Output is correct
83 Correct 25 ms 1268 KB Output is correct
84 Correct 55 ms 1924 KB Output is correct
85 Correct 11 ms 840 KB Output is correct
86 Correct 2 ms 384 KB Output is correct
87 Correct 50 ms 1688 KB Output is correct
88 Correct 2 ms 256 KB Output is correct
89 Correct 2 ms 384 KB Output is correct
90 Correct 2 ms 384 KB Output is correct
91 Correct 17 ms 1320 KB Output is correct
92 Correct 87 ms 4616 KB Output is correct
93 Correct 1285 ms 36688 KB Output is correct
94 Correct 870 ms 23072 KB Output is correct
95 Correct 977 ms 22460 KB Output is correct
96 Correct 778 ms 18788 KB Output is correct
97 Correct 624 ms 16320 KB Output is correct
98 Correct 1391 ms 35984 KB Output is correct
99 Correct 1534 ms 34488 KB Output is correct
100 Correct 1354 ms 34476 KB Output is correct
101 Correct 1187 ms 23876 KB Output is correct
102 Correct 992 ms 20944 KB Output is correct
103 Correct 1076 ms 24568 KB Output is correct
104 Correct 2 ms 384 KB Output is correct
105 Correct 2 ms 384 KB Output is correct
106 Correct 4 ms 512 KB Output is correct
107 Correct 68 ms 2784 KB Output is correct
108 Correct 242 ms 8736 KB Output is correct
109 Correct 23 ms 1404 KB Output is correct
110 Correct 2 ms 384 KB Output is correct
111 Correct 112 ms 4508 KB Output is correct
112 Correct 3 ms 384 KB Output is correct
113 Correct 2 ms 384 KB Output is correct
114 Correct 7 ms 768 KB Output is correct
115 Correct 2 ms 256 KB Output is correct
116 Correct 11 ms 948 KB Output is correct
117 Correct 377 ms 15120 KB Output is correct