Submission #825956

# Submission time Handle Problem Language Result Execution time Memory
825956 2023-08-15T09:31:36 Z Tsovak Toys (CEOI18_toy) C++17
100 / 100
2455 ms 16880 KB
// -------------------- Includes -------------------- //
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <stdlib.h>
#include <array>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <list>
#include <iterator>
#include <numeric>
#include <complex>
#include <tuple>
#include <utility>
#include <cassert>
#include <assert.h>
#include <climits>
#include <limits.h>
#include <ctime>
#include <time.h>
#include <random>
#include <chrono>
#include <fstream>
using namespace std;

// -------------------- Typedefs -------------------- //

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;

// -------------------- Defines -------------------- //

#define pr pair
#define mpr make_pair
#define ff first
#define ss second

#define mset multiset
#define mmap multimap
#define uset unordered_set
#define umap unordered_map
#define umset unordered_multiset
#define ummap unordered_multimap
#define pqueue priority_queue

#define sz(x) (int((x).size()))
#define len(x) (int((x).length()))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define clr(x) (x).clear()

#define pf push_front
#define pb push_back
#define popf pop_front
#define popb pop_back
#define ft front
#define bk back

#define lb lower_bound
#define ub upper_bound
#define bs binary_search

// -------------------- Constants -------------------- //

const int MAX = int(1e9 + 5);
const ll MAXL = ll(1e18 + 5);
const ll MOD = ll(1e9 + 7);
const ll MOD2 = ll(998244353);

// -------------------- Functions -------------------- //

void fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	return;
}

void precision(int x)
{
	cout.setf(ios::fixed | ios::showpoint);
	cout.precision(x);
	return;
}

ll gcd(ll a, ll b)
{
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}

bool is_prime(ll a)
{
	if (a == 1) {
		return false;
	}
	for (ll i = 2; i * i <= a; i++) {
		if (a % i == 0) {
			return false;
		}
	}
	return true;
}

bool is_square(ll a)
{
	ll b = ll(sqrt(a));
	return (b * b == a);
}

bool is_cube(ll a)
{
	ll b = ll(cbrt(a));
	return (b * b * b == a);
}

int digit_sum(ll a)
{
	int sum = 0;
	while (a) {
		sum += int(a % 10);
		a /= 10;
	}
	return sum;
}

ll binpow(ll a, int b)
{
	ll ans = 1;
	while (b) {
		if ((b & 1) == 1) {
			ans *= a;
		}
		b >>= 1;
		a *= a;
	}
	return ans;
}

ll binpow_by_mod(ll a, ll b, ll mod)
{
	ll ans = 1;
	while (b) {
		if ((b & 1) == 1) {
			ans *= a;
			ans %= mod;
		}
		b >>= 1;
		a *= a;
		a %= mod;
	}
	return ans;
}

ll factorial(int a)
{
	ll ans = 1;
	for (int i = 2; i <= a; i++) {
		ans *= ll(i);
	}
	return ans;
}

ll factorial_by_mod(int a, ll mod)
{
	ll ans = 1;
	for (int i = 2; i <= a; i++) {
		ans *= ll(i);
		ans %= mod;
	}
	return ans;
}

// -------------------- Solution -------------------- //

/*const int N = 200005;
int a[N];
int n;*/

vector<int> v;

vector<int> ans, ans0;

void rec(int n, int m, int s, int j)
{
	if (m == 0) {
		if (n == 1) ans.pb(s);
		return;
	}

	for (int i = j; i < sz(v) && binpow(v[i], m) <= n; i++) {
		if (n % v[i] == 0) rec(n / v[i], m - 1, s + v[i] - 1, i);
	}

	return;
}

void solve()
{
	int i, j;

	int n;
	cin >> n;

	if (n == 1) {
		cout << "1\n0\n";
		return;
	}

	for (i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			v.pb(i);
			if (i * i != n) v.pb(n / i);
		}
	}
	v.pb(n);

	sort(all(v));

	for (i = 1; i <= 30; i++) {
		rec(n, i, 0, 0);
	}

	sort(all(ans));

	for (i = 0; i < sz(ans); i++) {
		if (ans0.empty() || ans0.bk() < ans[i]) ans0.pb(ans[i]);
	}

	cout << sz(ans0) << "\n";
	for (i = 0; i < sz(ans0); i++) cout << ans0[i] << ' ';
	cout << "\n";

	return;
}

void precalc()
{
	return;
}

int main()
{
	fastio();

	precalc();

	int tests = 1, tc;
	//cin >> tests;
	for (tc = 1; tc <= tests; tc++) {
		solve();
	}

	//cout << db(clock()) / CLOCKS_PER_SEC << endl;

	return 0;
}

/*
	# # # #   # # # #   # # # #   #       #    #       #     #
	   #      #         #     #    #     #    # #      #   #
	   #      # # # #   #     #     #   #    #   #     # #
	   #            #   #     #      # #    # # # #    #   #
	   #      # # # #   # # # #       #    #       #   #     #
*/

Compilation message

toy.cpp: In function 'void solve()':
toy.cpp:227:9: warning: unused variable 'j' [-Wunused-variable]
  227 |  int i, j;
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 320 KB Output is correct
20 Correct 0 ms 324 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 320 KB Output is correct
20 Correct 0 ms 324 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 312 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 316 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 320 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 220 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 1 ms 216 KB Output is correct
39 Correct 0 ms 332 KB Output is correct
40 Correct 1 ms 324 KB Output is correct
41 Correct 1 ms 324 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 324 KB Output is correct
44 Correct 1 ms 220 KB Output is correct
45 Correct 0 ms 220 KB Output is correct
46 Correct 0 ms 320 KB Output is correct
47 Correct 1 ms 220 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 320 KB Output is correct
20 Correct 0 ms 324 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 312 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 316 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 320 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 220 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 1 ms 216 KB Output is correct
39 Correct 0 ms 332 KB Output is correct
40 Correct 1 ms 324 KB Output is correct
41 Correct 1 ms 324 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 324 KB Output is correct
44 Correct 1 ms 220 KB Output is correct
45 Correct 0 ms 220 KB Output is correct
46 Correct 0 ms 320 KB Output is correct
47 Correct 1 ms 220 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 320 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 328 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 1 ms 320 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 1 ms 344 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 0 ms 212 KB Output is correct
68 Correct 1 ms 212 KB Output is correct
69 Correct 0 ms 320 KB Output is correct
70 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 320 KB Output is correct
20 Correct 0 ms 324 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 312 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 316 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 320 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 220 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 1 ms 216 KB Output is correct
39 Correct 0 ms 332 KB Output is correct
40 Correct 1 ms 324 KB Output is correct
41 Correct 1 ms 324 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 324 KB Output is correct
44 Correct 1 ms 220 KB Output is correct
45 Correct 0 ms 220 KB Output is correct
46 Correct 0 ms 320 KB Output is correct
47 Correct 1 ms 220 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 320 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 328 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 1 ms 320 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 1 ms 344 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 0 ms 212 KB Output is correct
68 Correct 1 ms 212 KB Output is correct
69 Correct 0 ms 320 KB Output is correct
70 Correct 1 ms 212 KB Output is correct
71 Correct 187 ms 2460 KB Output is correct
72 Correct 115 ms 1408 KB Output is correct
73 Correct 188 ms 2404 KB Output is correct
74 Correct 85 ms 944 KB Output is correct
75 Correct 103 ms 1448 KB Output is correct
76 Correct 365 ms 4524 KB Output is correct
77 Correct 331 ms 4524 KB Output is correct
78 Correct 253 ms 2468 KB Output is correct
79 Correct 253 ms 2564 KB Output is correct
80 Correct 1 ms 212 KB Output is correct
81 Correct 1 ms 212 KB Output is correct
82 Correct 1 ms 320 KB Output is correct
83 Correct 11 ms 696 KB Output is correct
84 Correct 16 ms 728 KB Output is correct
85 Correct 2 ms 340 KB Output is correct
86 Correct 1 ms 212 KB Output is correct
87 Correct 15 ms 632 KB Output is correct
88 Correct 1 ms 212 KB Output is correct
89 Correct 1 ms 212 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 5 ms 428 KB Output is correct
92 Correct 31 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 320 KB Output is correct
20 Correct 0 ms 324 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 312 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 316 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 320 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 220 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 1 ms 216 KB Output is correct
39 Correct 0 ms 332 KB Output is correct
40 Correct 1 ms 324 KB Output is correct
41 Correct 1 ms 324 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 324 KB Output is correct
44 Correct 1 ms 220 KB Output is correct
45 Correct 0 ms 220 KB Output is correct
46 Correct 0 ms 320 KB Output is correct
47 Correct 1 ms 220 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 320 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 328 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 1 ms 320 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 1 ms 344 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 0 ms 212 KB Output is correct
68 Correct 1 ms 212 KB Output is correct
69 Correct 0 ms 320 KB Output is correct
70 Correct 1 ms 212 KB Output is correct
71 Correct 187 ms 2460 KB Output is correct
72 Correct 115 ms 1408 KB Output is correct
73 Correct 188 ms 2404 KB Output is correct
74 Correct 85 ms 944 KB Output is correct
75 Correct 103 ms 1448 KB Output is correct
76 Correct 365 ms 4524 KB Output is correct
77 Correct 331 ms 4524 KB Output is correct
78 Correct 253 ms 2468 KB Output is correct
79 Correct 253 ms 2564 KB Output is correct
80 Correct 1 ms 212 KB Output is correct
81 Correct 1 ms 212 KB Output is correct
82 Correct 1 ms 320 KB Output is correct
83 Correct 11 ms 696 KB Output is correct
84 Correct 16 ms 728 KB Output is correct
85 Correct 2 ms 340 KB Output is correct
86 Correct 1 ms 212 KB Output is correct
87 Correct 15 ms 632 KB Output is correct
88 Correct 1 ms 212 KB Output is correct
89 Correct 1 ms 212 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 5 ms 428 KB Output is correct
92 Correct 31 ms 600 KB Output is correct
93 Correct 1851 ms 9476 KB Output is correct
94 Correct 780 ms 4536 KB Output is correct
95 Correct 989 ms 8604 KB Output is correct
96 Correct 861 ms 4976 KB Output is correct
97 Correct 771 ms 4928 KB Output is correct
98 Correct 2146 ms 16848 KB Output is correct
99 Correct 2455 ms 16804 KB Output is correct
100 Correct 2118 ms 16796 KB Output is correct
101 Correct 2099 ms 16816 KB Output is correct
102 Correct 1712 ms 16880 KB Output is correct
103 Correct 1124 ms 8648 KB Output is correct
104 Correct 1 ms 212 KB Output is correct
105 Correct 1 ms 212 KB Output is correct
106 Correct 1 ms 380 KB Output is correct
107 Correct 42 ms 1512 KB Output is correct
108 Correct 157 ms 2600 KB Output is correct
109 Correct 5 ms 468 KB Output is correct
110 Correct 1 ms 212 KB Output is correct
111 Correct 51 ms 1464 KB Output is correct
112 Correct 1 ms 212 KB Output is correct
113 Correct 1 ms 320 KB Output is correct
114 Correct 2 ms 340 KB Output is correct
115 Correct 1 ms 320 KB Output is correct
116 Correct 3 ms 340 KB Output is correct
117 Correct 188 ms 1576 KB Output is correct