Submission #893604

# Submission time Handle Problem Language Result Execution time Memory
893604 2023-12-27T07:25:01 Z vjudge1 Toys (CEOI18_toy) C++17
79 / 100
5000 ms 31796 KB
#include<bits/stdc++.h>

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
#define int ll
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mispertion ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define F first
#define S second
#define getlast(s) (*s.rbegin())
#define debg cout << "OK\n"

const ld PI = 3.1415926535;
const int N = 5e3 + 2;
const int M = 7e6 + 1;
int mod = 1e9+7;
const int infi = INT_MAX;
const ll infl = LLONG_MAX;
const int P = 31;

int mult(int a, int b) {
    return a * 1LL * b % mod;
}

int sum(int a, int b) {
    a %= mod; 
    if (a + b < 0)
        return a + b + mod;
    if (a + b >= mod)
        return a + b - mod;
    return a + b;
}

ll binpow(ll a, ll n) {
    if (n == 0)
        return 1;
    if (n % 2 == 1) {
        return binpow(a, n - 1) * a % mod;
    } else {
        ll b = binpow(a, n / 2);
        return b * b % mod;
    }
}

vector<int> ds;
map<int, int> mp;
set<int> st;

void getans(int n, int cs = 0, int mx = 0){
    if(cs + n - 1 <= 5e3)
        return;
    if(n == 1){
        st.insert(cs);
        return;
    }
    for(auto d : ds){
        if(n % d == 0 && d >= mx)
            getans(n / d, cs + d - 1, d);
    }
}

void solve(){
    int n;
    cin >> n;
    if(n == 1){
        cout << 1 << '\n' << 0 << '\n';
        return;
    }
    for(int i = 2; i * i <= n; i++){
        if(n % i)
            continue;
        ds.pb(i);
        if(i * i != n)
            ds.pb(n / i);
    }
    ds.pb(n);
    getans(n);
    ds.pb(1);
    sort(all(ds));
    for(int i = 0; i < sz(ds); i++)
        mp[ds[i]] = i;
    int dp[sz(ds)][N];
    memset(dp, 0, sizeof dp);
    dp[0][0] = 1;
    for(int i = 1; i < sz(ds); i++){
        int x = ds[i];
        vector<int> da = {};
        for(auto d : ds)
            if(x % d == 0)
                da.pb(d);
        for(int s = 0; s < N; s++){
            for(auto d : da){
                if(s - d + 1 < 0)
                    continue;
                dp[i][s] |= dp[mp[x / d]][s - d + 1];
            }
        }
    }
    for(int i = 0; i < N; i++)
        if(dp[sz(ds) - 1][i])
            st.insert(i);
    cout << sz(st) << '\n';
    for(auto e : st)
        cout << e << ' ';
    cout << '\n';
}   

signed main() {
    mispertion;
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 856 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 856 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 44 ms 2908 KB Output is correct
27 Correct 35 ms 2800 KB Output is correct
28 Correct 22 ms 2136 KB Output is correct
29 Correct 16 ms 1884 KB Output is correct
30 Correct 13 ms 1628 KB Output is correct
31 Correct 36 ms 2624 KB Output is correct
32 Correct 34 ms 2644 KB Output is correct
33 Correct 32 ms 2396 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 1 ms 360 KB Output is correct
36 Correct 4 ms 860 KB Output is correct
37 Correct 18 ms 1864 KB Output is correct
38 Correct 8 ms 1372 KB Output is correct
39 Correct 3 ms 860 KB Output is correct
40 Correct 25 ms 2336 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 6 ms 1396 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 12 ms 1864 KB Output is correct
46 Correct 2 ms 860 KB Output is correct
47 Correct 16 ms 1880 KB Output is correct
48 Correct 1 ms 600 KB Output is correct
49 Correct 10 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 856 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 44 ms 2908 KB Output is correct
27 Correct 35 ms 2800 KB Output is correct
28 Correct 22 ms 2136 KB Output is correct
29 Correct 16 ms 1884 KB Output is correct
30 Correct 13 ms 1628 KB Output is correct
31 Correct 36 ms 2624 KB Output is correct
32 Correct 34 ms 2644 KB Output is correct
33 Correct 32 ms 2396 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 1 ms 360 KB Output is correct
36 Correct 4 ms 860 KB Output is correct
37 Correct 18 ms 1864 KB Output is correct
38 Correct 8 ms 1372 KB Output is correct
39 Correct 3 ms 860 KB Output is correct
40 Correct 25 ms 2336 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 6 ms 1396 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 12 ms 1864 KB Output is correct
46 Correct 2 ms 860 KB Output is correct
47 Correct 16 ms 1880 KB Output is correct
48 Correct 1 ms 600 KB Output is correct
49 Correct 10 ms 1628 KB Output is correct
50 Correct 131 ms 5464 KB Output is correct
51 Correct 122 ms 4956 KB Output is correct
52 Correct 108 ms 4680 KB Output is correct
53 Correct 95 ms 4348 KB Output is correct
54 Correct 77 ms 4440 KB Output is correct
55 Correct 137 ms 5140 KB Output is correct
56 Correct 115 ms 4664 KB Output is correct
57 Correct 138 ms 5136 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 1 ms 604 KB Output is correct
60 Correct 5 ms 1116 KB Output is correct
61 Correct 41 ms 2640 KB Output is correct
62 Correct 43 ms 2948 KB Output is correct
63 Correct 16 ms 1624 KB Output is correct
64 Correct 2 ms 856 KB Output is correct
65 Correct 58 ms 3164 KB Output is correct
66 Correct 1 ms 604 KB Output is correct
67 Correct 1 ms 604 KB Output is correct
68 Correct 5 ms 1396 KB Output is correct
69 Correct 20 ms 2308 KB Output is correct
70 Correct 66 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 856 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 44 ms 2908 KB Output is correct
27 Correct 35 ms 2800 KB Output is correct
28 Correct 22 ms 2136 KB Output is correct
29 Correct 16 ms 1884 KB Output is correct
30 Correct 13 ms 1628 KB Output is correct
31 Correct 36 ms 2624 KB Output is correct
32 Correct 34 ms 2644 KB Output is correct
33 Correct 32 ms 2396 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 1 ms 360 KB Output is correct
36 Correct 4 ms 860 KB Output is correct
37 Correct 18 ms 1864 KB Output is correct
38 Correct 8 ms 1372 KB Output is correct
39 Correct 3 ms 860 KB Output is correct
40 Correct 25 ms 2336 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 6 ms 1396 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 12 ms 1864 KB Output is correct
46 Correct 2 ms 860 KB Output is correct
47 Correct 16 ms 1880 KB Output is correct
48 Correct 1 ms 600 KB Output is correct
49 Correct 10 ms 1628 KB Output is correct
50 Correct 131 ms 5464 KB Output is correct
51 Correct 122 ms 4956 KB Output is correct
52 Correct 108 ms 4680 KB Output is correct
53 Correct 95 ms 4348 KB Output is correct
54 Correct 77 ms 4440 KB Output is correct
55 Correct 137 ms 5140 KB Output is correct
56 Correct 115 ms 4664 KB Output is correct
57 Correct 138 ms 5136 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 1 ms 604 KB Output is correct
60 Correct 5 ms 1116 KB Output is correct
61 Correct 41 ms 2640 KB Output is correct
62 Correct 43 ms 2948 KB Output is correct
63 Correct 16 ms 1624 KB Output is correct
64 Correct 2 ms 856 KB Output is correct
65 Correct 58 ms 3164 KB Output is correct
66 Correct 1 ms 604 KB Output is correct
67 Correct 1 ms 604 KB Output is correct
68 Correct 5 ms 1396 KB Output is correct
69 Correct 20 ms 2308 KB Output is correct
70 Correct 66 ms 4188 KB Output is correct
71 Correct 3297 ms 31608 KB Output is correct
72 Correct 2689 ms 30008 KB Output is correct
73 Correct 2698 ms 27688 KB Output is correct
74 Correct 2390 ms 26244 KB Output is correct
75 Correct 2091 ms 24616 KB Output is correct
76 Correct 4497 ms 31796 KB Output is correct
77 Correct 3085 ms 25088 KB Output is correct
78 Correct 2975 ms 28160 KB Output is correct
79 Correct 2874 ms 26592 KB Output is correct
80 Correct 0 ms 600 KB Output is correct
81 Correct 1 ms 348 KB Output is correct
82 Correct 11 ms 1532 KB Output is correct
83 Correct 178 ms 5320 KB Output is correct
84 Correct 423 ms 9080 KB Output is correct
85 Correct 88 ms 3692 KB Output is correct
86 Correct 16 ms 2136 KB Output is correct
87 Correct 350 ms 8364 KB Output is correct
88 Correct 3 ms 860 KB Output is correct
89 Correct 1 ms 604 KB Output is correct
90 Correct 14 ms 2140 KB Output is correct
91 Correct 327 ms 9968 KB Output is correct
92 Correct 1422 ms 23776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 856 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 44 ms 2908 KB Output is correct
27 Correct 35 ms 2800 KB Output is correct
28 Correct 22 ms 2136 KB Output is correct
29 Correct 16 ms 1884 KB Output is correct
30 Correct 13 ms 1628 KB Output is correct
31 Correct 36 ms 2624 KB Output is correct
32 Correct 34 ms 2644 KB Output is correct
33 Correct 32 ms 2396 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 1 ms 360 KB Output is correct
36 Correct 4 ms 860 KB Output is correct
37 Correct 18 ms 1864 KB Output is correct
38 Correct 8 ms 1372 KB Output is correct
39 Correct 3 ms 860 KB Output is correct
40 Correct 25 ms 2336 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 6 ms 1396 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 12 ms 1864 KB Output is correct
46 Correct 2 ms 860 KB Output is correct
47 Correct 16 ms 1880 KB Output is correct
48 Correct 1 ms 600 KB Output is correct
49 Correct 10 ms 1628 KB Output is correct
50 Correct 131 ms 5464 KB Output is correct
51 Correct 122 ms 4956 KB Output is correct
52 Correct 108 ms 4680 KB Output is correct
53 Correct 95 ms 4348 KB Output is correct
54 Correct 77 ms 4440 KB Output is correct
55 Correct 137 ms 5140 KB Output is correct
56 Correct 115 ms 4664 KB Output is correct
57 Correct 138 ms 5136 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 1 ms 604 KB Output is correct
60 Correct 5 ms 1116 KB Output is correct
61 Correct 41 ms 2640 KB Output is correct
62 Correct 43 ms 2948 KB Output is correct
63 Correct 16 ms 1624 KB Output is correct
64 Correct 2 ms 856 KB Output is correct
65 Correct 58 ms 3164 KB Output is correct
66 Correct 1 ms 604 KB Output is correct
67 Correct 1 ms 604 KB Output is correct
68 Correct 5 ms 1396 KB Output is correct
69 Correct 20 ms 2308 KB Output is correct
70 Correct 66 ms 4188 KB Output is correct
71 Correct 3297 ms 31608 KB Output is correct
72 Correct 2689 ms 30008 KB Output is correct
73 Correct 2698 ms 27688 KB Output is correct
74 Correct 2390 ms 26244 KB Output is correct
75 Correct 2091 ms 24616 KB Output is correct
76 Correct 4497 ms 31796 KB Output is correct
77 Correct 3085 ms 25088 KB Output is correct
78 Correct 2975 ms 28160 KB Output is correct
79 Correct 2874 ms 26592 KB Output is correct
80 Correct 0 ms 600 KB Output is correct
81 Correct 1 ms 348 KB Output is correct
82 Correct 11 ms 1532 KB Output is correct
83 Correct 178 ms 5320 KB Output is correct
84 Correct 423 ms 9080 KB Output is correct
85 Correct 88 ms 3692 KB Output is correct
86 Correct 16 ms 2136 KB Output is correct
87 Correct 350 ms 8364 KB Output is correct
88 Correct 3 ms 860 KB Output is correct
89 Correct 1 ms 604 KB Output is correct
90 Correct 14 ms 2140 KB Output is correct
91 Correct 327 ms 9968 KB Output is correct
92 Correct 1422 ms 23776 KB Output is correct
93 Execution timed out 5086 ms 2728 KB Time limit exceeded
94 Halted 0 ms 0 KB -