Submission #385749

# Submission time Handle Problem Language Result Execution time Memory
385749 2021-04-04T21:17:18 Z mohamedsobhi777 Toys (CEOI18_toy) C++14
79 / 100
5000 ms 4144 KB
#include <bits/stdc++.h>

using namespace std;

#define vi vector<int>
#define vll vector<ll>
#define vii vector<pair<int, int>>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define loop(_) for (int __ = 0; __ < (_); ++__)
#define pb push_back
#define f first
#define s second
#define sz(_) ((int)_.size())
#define all(_) _.begin(), _.end()
#define lb lower_bound
#define ub upper_bound

using ll = long long;
using ld = long double;

const int N = 1e5 + 7;
const ll mod = 1e9 + 7;

int n;
set<int> ans;
vi prm;

vi facto(int x)
{
       vi ret;
       for (int i = 2; i * i <= x; ++i)
       {
              while (x % i == 0)
              {
                     ret.pb(i);
                     x /= i;
              }
       }
       if (x > 1)
              ret.pb(x);
       return ret;
}

int sum;
int tkn = 0;
int lst = 0;

void backtrack()
{
       if (tkn == (1 << sz(prm)) - 1)
       {
              ans.insert(sum);
              return;
       }
       int ntkn = (tkn ^ ((1 << sz(prm)) - 1));
       for (int i = ntkn; i; i = (i - 1) & ntkn)
       {
              // if ((tkn & i))
              // continue;
              int asum = 1;
              bool flag = 0;
              for (int j = 0; j < sz(prm); ++j)
              {
                     if (i & (1 << j))
                     {
                            asum *= prm[j];
                            auto got = [&](int u, int z) -> bool {
                                   return (u >> z) & 1;
                            };
                            if (j && prm[j] == prm[j - 1] && !got(tkn, j - 1) && !got(i, j - 1))
                            {
                                   flag = 1;
                                   break;
                            }
                     }
              }
              if (flag || asum < lst)
                     continue;
              sum += asum - 1;
              int omask = tkn;
              int olst = lst;
              tkn |= i;
              lst = asum ;
              backtrack();
              tkn = omask;
              lst = olst;
              sum -= asum - 1;
       }
}

vii prep(vi x)
{
       vii ret;
       int z = sz(x);
       for (int i = 0; i < (1 << z); ++i)
       {
              int mul = 1;
              for (int j = 0; j < z; ++j)
              {
                     if (i & (1 << j))
                     {
                            mul *= x[j];
                     }
              }
              ret.pb({__builtin_popcount(i), mul});
       }

       return ret;
}

int main()
{
       ios_base::sync_with_stdio(0);
       cin.tie(0);
#ifndef ONLINE_JUDGE
#endif
       cin >> n;
       // n = (1 << 26);
       prm = facto(n);
       sort(all(prm));
       vi lhs, rhs;

       for (int i = 0; i < sz(prm); ++i)
       {
              if (i < sz(prm) / 2)
                     lhs.pb(prm[i]);
              else
                     rhs.pb(prm[i]);
       }
       // vii LHS = prep(lhs), RHS = prep(rhs);
       // for(int auto u : LHS){
       //        for(auto u2:RHS){

       //        }
       // }
       backtrack();
       cout << sz(ans) << "\n";
       for (auto u : ans)
       {
              cout << u << " ";
       }
       return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 372 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 372 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 2 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 2 ms 364 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 1 ms 512 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 372 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 2 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 2 ms 364 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 1 ms 512 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 364 KB Output is correct
50 Correct 3 ms 364 KB Output is correct
51 Correct 3 ms 364 KB Output is correct
52 Correct 3 ms 364 KB Output is correct
53 Correct 3 ms 364 KB Output is correct
54 Correct 2 ms 364 KB Output is correct
55 Correct 5 ms 364 KB Output is correct
56 Correct 8 ms 364 KB Output is correct
57 Correct 4 ms 364 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 4 ms 364 KB Output is correct
61 Correct 5 ms 364 KB Output is correct
62 Correct 2 ms 364 KB Output is correct
63 Correct 1 ms 364 KB Output is correct
64 Correct 1 ms 364 KB Output is correct
65 Correct 3 ms 384 KB Output is correct
66 Correct 1 ms 364 KB Output is correct
67 Correct 1 ms 364 KB Output is correct
68 Correct 2 ms 364 KB Output is correct
69 Correct 1 ms 364 KB Output is correct
70 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 372 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 2 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 2 ms 364 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 1 ms 512 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 364 KB Output is correct
50 Correct 3 ms 364 KB Output is correct
51 Correct 3 ms 364 KB Output is correct
52 Correct 3 ms 364 KB Output is correct
53 Correct 3 ms 364 KB Output is correct
54 Correct 2 ms 364 KB Output is correct
55 Correct 5 ms 364 KB Output is correct
56 Correct 8 ms 364 KB Output is correct
57 Correct 4 ms 364 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 4 ms 364 KB Output is correct
61 Correct 5 ms 364 KB Output is correct
62 Correct 2 ms 364 KB Output is correct
63 Correct 1 ms 364 KB Output is correct
64 Correct 1 ms 364 KB Output is correct
65 Correct 3 ms 384 KB Output is correct
66 Correct 1 ms 364 KB Output is correct
67 Correct 1 ms 364 KB Output is correct
68 Correct 2 ms 364 KB Output is correct
69 Correct 1 ms 364 KB Output is correct
70 Correct 1 ms 364 KB Output is correct
71 Correct 402 ms 1516 KB Output is correct
72 Correct 202 ms 1260 KB Output is correct
73 Correct 570 ms 1260 KB Output is correct
74 Correct 160 ms 1132 KB Output is correct
75 Correct 279 ms 1132 KB Output is correct
76 Correct 1293 ms 1900 KB Output is correct
77 Correct 2406 ms 1792 KB Output is correct
78 Correct 1044 ms 1564 KB Output is correct
79 Correct 1321 ms 1868 KB Output is correct
80 Correct 1 ms 364 KB Output is correct
81 Correct 1 ms 364 KB Output is correct
82 Correct 3040 ms 760 KB Output is correct
83 Correct 632 ms 712 KB Output is correct
84 Correct 180 ms 748 KB Output is correct
85 Correct 37 ms 492 KB Output is correct
86 Correct 1 ms 364 KB Output is correct
87 Correct 189 ms 748 KB Output is correct
88 Correct 1 ms 364 KB Output is correct
89 Correct 1 ms 364 KB Output is correct
90 Correct 1 ms 364 KB Output is correct
91 Correct 10 ms 620 KB Output is correct
92 Correct 42 ms 1004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 372 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 2 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 2 ms 364 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 1 ms 512 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 364 KB Output is correct
50 Correct 3 ms 364 KB Output is correct
51 Correct 3 ms 364 KB Output is correct
52 Correct 3 ms 364 KB Output is correct
53 Correct 3 ms 364 KB Output is correct
54 Correct 2 ms 364 KB Output is correct
55 Correct 5 ms 364 KB Output is correct
56 Correct 8 ms 364 KB Output is correct
57 Correct 4 ms 364 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 4 ms 364 KB Output is correct
61 Correct 5 ms 364 KB Output is correct
62 Correct 2 ms 364 KB Output is correct
63 Correct 1 ms 364 KB Output is correct
64 Correct 1 ms 364 KB Output is correct
65 Correct 3 ms 384 KB Output is correct
66 Correct 1 ms 364 KB Output is correct
67 Correct 1 ms 364 KB Output is correct
68 Correct 2 ms 364 KB Output is correct
69 Correct 1 ms 364 KB Output is correct
70 Correct 1 ms 364 KB Output is correct
71 Correct 402 ms 1516 KB Output is correct
72 Correct 202 ms 1260 KB Output is correct
73 Correct 570 ms 1260 KB Output is correct
74 Correct 160 ms 1132 KB Output is correct
75 Correct 279 ms 1132 KB Output is correct
76 Correct 1293 ms 1900 KB Output is correct
77 Correct 2406 ms 1792 KB Output is correct
78 Correct 1044 ms 1564 KB Output is correct
79 Correct 1321 ms 1868 KB Output is correct
80 Correct 1 ms 364 KB Output is correct
81 Correct 1 ms 364 KB Output is correct
82 Correct 3040 ms 760 KB Output is correct
83 Correct 632 ms 712 KB Output is correct
84 Correct 180 ms 748 KB Output is correct
85 Correct 37 ms 492 KB Output is correct
86 Correct 1 ms 364 KB Output is correct
87 Correct 189 ms 748 KB Output is correct
88 Correct 1 ms 364 KB Output is correct
89 Correct 1 ms 364 KB Output is correct
90 Correct 1 ms 364 KB Output is correct
91 Correct 10 ms 620 KB Output is correct
92 Correct 42 ms 1004 KB Output is correct
93 Correct 4179 ms 4144 KB Output is correct
94 Correct 1190 ms 3308 KB Output is correct
95 Correct 2140 ms 3452 KB Output is correct
96 Correct 1800 ms 2984 KB Output is correct
97 Correct 2086 ms 2716 KB Output is correct
98 Execution timed out 5030 ms 3756 KB Time limit exceeded
99 Halted 0 ms 0 KB -