Submission #712589

# Submission time Handle Problem Language Result Execution time Memory
712589 2023-03-19T08:41:00 Z 600Mihnea Toys (CEOI18_toy) C++17
100 / 100
2185 ms 5220 KB
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <cassert>
#include <bitset>
#include <sstream>
#include <stack>
#include <chrono>
#include <cstring>
#include <numeric>

using namespace std;

typedef long long ll;

int n;
vector<int> dv;
vector<vector<int>> dvofdv;

int fnd(int x)
{
	int l = 0, r = (int)dv.size() - 1;
	while (l <= r)
	{
		int m = (l + r) / 2;
		if (dv[m] == x) return m;
		if (dv[m] < x) l = m + 1; else r = m - 1;
	}
	assert(0);
}

set<int> gustav;

void back(int x, int s, int mx)
{
	assert(x >= 2);
	gustav.insert(s + (x - 1));
	int p = fnd(x);
	for (auto& divizor : dvofdv[p])
	{
		if (divizor > mx) return;
		if (divizor > 1 && x / divizor > 1)
		{
			back(x / divizor, s + (divizor - 1), divizor);
		}
	}
}

signed main()
{
#ifdef ONPC	
	FILE* stream;
	freopen_s(&stream, "input.txt", "r", stdin);
#else
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif
	
	cin >> n;
	if (n == 1)
	{
		cout << "1\n";
		cout << "0\n";
		return 0;
	}
	for (int i = 1; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			dv.push_back(i);
			if (i * i == n) continue;
			dv.push_back(n / i);
		}
	}
	sort(dv.begin(), dv.end());
	dvofdv.resize((int)dv.size());
	for (int i = 0; i < (int)dv.size(); i++)
	{
		for (auto& x : dv)
		{
			if (x *(ll) x > dv[i]) break;
			if (dv[i] % x == 0)
			{
				dvofdv[i].push_back(x);
				if (x * x == dv[i]) continue;
				dvofdv[i].push_back(dv[i] / x);
			}
		}
		sort(dvofdv[i].begin(), dvofdv[i].end());
	}

	back(n, 0, n);
	cout << (int)gustav.size() << "\n";
	for (auto& x : gustav)
	{
		cout << x << " ";
	}
	cout << "\n";

	return 0;
}
# 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 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 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 212 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 2 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 316 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 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 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 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 212 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 2 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 316 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 312 KB Output is correct
29 Correct 1 ms 320 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 316 KB Output is correct
32 Correct 1 ms 320 KB Output is correct
33 Correct 1 ms 308 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 324 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 256 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 372 KB Output is correct
48 Correct 1 ms 320 KB Output is correct
49 Correct 1 ms 316 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 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 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 212 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 2 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 316 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 312 KB Output is correct
29 Correct 1 ms 320 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 316 KB Output is correct
32 Correct 1 ms 320 KB Output is correct
33 Correct 1 ms 308 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 324 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 256 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 372 KB Output is correct
48 Correct 1 ms 320 KB Output is correct
49 Correct 1 ms 316 KB Output is correct
50 Correct 2 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 2 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 2 ms 340 KB Output is correct
56 Correct 2 ms 340 KB Output is correct
57 Correct 2 ms 340 KB Output is correct
58 Correct 1 ms 316 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 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 324 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 1 ms 212 KB Output is correct
68 Correct 1 ms 212 KB Output is correct
69 Correct 1 ms 212 KB Output is correct
70 Correct 1 ms 340 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 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 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 212 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 2 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 316 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 312 KB Output is correct
29 Correct 1 ms 320 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 316 KB Output is correct
32 Correct 1 ms 320 KB Output is correct
33 Correct 1 ms 308 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 324 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 256 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 372 KB Output is correct
48 Correct 1 ms 320 KB Output is correct
49 Correct 1 ms 316 KB Output is correct
50 Correct 2 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 2 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 2 ms 340 KB Output is correct
56 Correct 2 ms 340 KB Output is correct
57 Correct 2 ms 340 KB Output is correct
58 Correct 1 ms 316 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 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 324 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 1 ms 212 KB Output is correct
68 Correct 1 ms 212 KB Output is correct
69 Correct 1 ms 212 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 168 ms 1784 KB Output is correct
72 Correct 96 ms 1432 KB Output is correct
73 Correct 181 ms 1428 KB Output is correct
74 Correct 77 ms 1352 KB Output is correct
75 Correct 103 ms 1172 KB Output is correct
76 Correct 339 ms 2052 KB Output is correct
77 Correct 392 ms 1768 KB Output is correct
78 Correct 259 ms 1712 KB Output is correct
79 Correct 309 ms 1712 KB Output is correct
80 Correct 1 ms 212 KB Output is correct
81 Correct 1 ms 212 KB Output is correct
82 Correct 2 ms 340 KB Output is correct
83 Correct 26 ms 632 KB Output is correct
84 Correct 28 ms 700 KB Output is correct
85 Correct 4 ms 468 KB Output is correct
86 Correct 1 ms 212 KB Output is correct
87 Correct 27 ms 724 KB Output is correct
88 Correct 1 ms 212 KB Output is correct
89 Correct 1 ms 316 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 8 ms 596 KB Output is correct
92 Correct 29 ms 1088 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 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 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 212 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 2 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 316 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 312 KB Output is correct
29 Correct 1 ms 320 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 316 KB Output is correct
32 Correct 1 ms 320 KB Output is correct
33 Correct 1 ms 308 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 324 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 256 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 372 KB Output is correct
48 Correct 1 ms 320 KB Output is correct
49 Correct 1 ms 316 KB Output is correct
50 Correct 2 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 2 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 2 ms 340 KB Output is correct
56 Correct 2 ms 340 KB Output is correct
57 Correct 2 ms 340 KB Output is correct
58 Correct 1 ms 316 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 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 324 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 1 ms 212 KB Output is correct
68 Correct 1 ms 212 KB Output is correct
69 Correct 1 ms 212 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 168 ms 1784 KB Output is correct
72 Correct 96 ms 1432 KB Output is correct
73 Correct 181 ms 1428 KB Output is correct
74 Correct 77 ms 1352 KB Output is correct
75 Correct 103 ms 1172 KB Output is correct
76 Correct 339 ms 2052 KB Output is correct
77 Correct 392 ms 1768 KB Output is correct
78 Correct 259 ms 1712 KB Output is correct
79 Correct 309 ms 1712 KB Output is correct
80 Correct 1 ms 212 KB Output is correct
81 Correct 1 ms 212 KB Output is correct
82 Correct 2 ms 340 KB Output is correct
83 Correct 26 ms 632 KB Output is correct
84 Correct 28 ms 700 KB Output is correct
85 Correct 4 ms 468 KB Output is correct
86 Correct 1 ms 212 KB Output is correct
87 Correct 27 ms 724 KB Output is correct
88 Correct 1 ms 212 KB Output is correct
89 Correct 1 ms 316 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 8 ms 596 KB Output is correct
92 Correct 29 ms 1088 KB Output is correct
93 Correct 1388 ms 4892 KB Output is correct
94 Correct 535 ms 3820 KB Output is correct
95 Correct 780 ms 3808 KB Output is correct
96 Correct 634 ms 3456 KB Output is correct
97 Correct 640 ms 3004 KB Output is correct
98 Correct 1670 ms 5216 KB Output is correct
99 Correct 2111 ms 5220 KB Output is correct
100 Correct 1754 ms 5004 KB Output is correct
101 Correct 2185 ms 4640 KB Output is correct
102 Correct 1813 ms 4384 KB Output is correct
103 Correct 835 ms 4232 KB Output is correct
104 Correct 1 ms 212 KB Output is correct
105 Correct 1 ms 212 KB Output is correct
106 Correct 3 ms 340 KB Output is correct
107 Correct 115 ms 1220 KB Output is correct
108 Correct 261 ms 2068 KB Output is correct
109 Correct 11 ms 724 KB Output is correct
110 Correct 1 ms 212 KB Output is correct
111 Correct 92 ms 1476 KB Output is correct
112 Correct 1 ms 212 KB Output is correct
113 Correct 1 ms 212 KB Output is correct
114 Correct 3 ms 468 KB Output is correct
115 Correct 1 ms 212 KB Output is correct
116 Correct 4 ms 596 KB Output is correct
117 Correct 128 ms 2496 KB Output is correct