답안 #826088

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
826088 2023-08-15T10:18:15 Z dxz05 Toys (CEOI18_toy) C++17
100 / 100
1990 ms 31212 KB
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("avx,avx2")

#include <bits/stdc++.h>
 
using namespace std;

#define all(x) (x).begin(), (x).end()

set<pair<int, int>> dp[1500];

void add_segment(int l, int r, set<pair<int, int>> &s){
	s.emplace(l, r);
	auto it = s.find(make_pair(l, r));
	
	if (next(it) != s.end()){
		auto nit = next(it);
		if (nit->first <= r + 1){
			l = min(l, nit->first);
			r = max(r, nit->second);
			s.erase(nit);
			s.erase(it);
			s.emplace(l, r);
			it = s.find(make_pair(l, r));
		}
	}
	
	if (it != s.begin()){
		auto pit = prev(it);
		if (pit->second >= l - 1){
			l = min(l, pit->first);
			r = max(r, pit->second);
			s.erase(it);
			s.erase(pit);
			s.emplace(l, r);
		}
	}
	
}

int main(){
	ios_base::sync_with_stdio(false);
	
	int n;
	cin >> n;
	
	vector<int> divisors;
	for (int d = 1; d * d <= n; d++){
		if (n % d == 0){
			divisors.push_back(d);
			if (n != d * d) divisors.push_back(n / d);
		}
	}
	
	sort(all(divisors));
	
	int m = (int) divisors.size();
	
	add_segment(0, 0, dp[0]);
	
	for (int i = 1; i < m; i++){
		int d = divisors[i];
		
		int k = m - 1;
		for (int j = 1; j <= i; j++){
			int x = divisors[j];
			if (d % x) continue;
			
			int _d = d / x;
			while (divisors[k] > _d) k--;
			
			for (auto [l, r] : dp[k]){
				add_segment(l + x - 1, r + x - 1, dp[i]);
			}
		}
	}
	
	int ans = 0;
	for (auto [l, r] : dp[m - 1]){
		ans += r - l + 1;
	}
	
	cout << ans << endl;
	for (auto [l, r] : dp[m - 1]){
		while (l <= r){
			cout << l << ' ';
			l++;
		}
	}
	cout << endl;
	
    return 0;
}

/*

735134400

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 392 KB Output is correct
8 Correct 0 ms 396 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 392 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 392 KB Output is correct
8 Correct 0 ms 396 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 392 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 428 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 396 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 396 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 ms 408 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 392 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 392 KB Output is correct
8 Correct 0 ms 396 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 392 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 428 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 396 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 396 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 ms 408 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 392 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 4 ms 532 KB Output is correct
51 Correct 3 ms 468 KB Output is correct
52 Correct 3 ms 468 KB Output is correct
53 Correct 3 ms 492 KB Output is correct
54 Correct 2 ms 468 KB Output is correct
55 Correct 4 ms 468 KB Output is correct
56 Correct 4 ms 520 KB Output is correct
57 Correct 4 ms 468 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 2 ms 452 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 0 ms 340 KB Output is correct
65 Correct 3 ms 388 KB Output is correct
66 Correct 0 ms 340 KB Output is correct
67 Correct 0 ms 340 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 392 KB Output is correct
8 Correct 0 ms 396 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 392 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 428 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 396 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 396 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 ms 408 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 392 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 4 ms 532 KB Output is correct
51 Correct 3 ms 468 KB Output is correct
52 Correct 3 ms 468 KB Output is correct
53 Correct 3 ms 492 KB Output is correct
54 Correct 2 ms 468 KB Output is correct
55 Correct 4 ms 468 KB Output is correct
56 Correct 4 ms 520 KB Output is correct
57 Correct 4 ms 468 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 2 ms 452 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 0 ms 340 KB Output is correct
65 Correct 3 ms 388 KB Output is correct
66 Correct 0 ms 340 KB Output is correct
67 Correct 0 ms 340 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 2 ms 468 KB Output is correct
71 Correct 366 ms 7860 KB Output is correct
72 Correct 273 ms 6796 KB Output is correct
73 Correct 275 ms 6288 KB Output is correct
74 Correct 207 ms 5188 KB Output is correct
75 Correct 229 ms 5304 KB Output is correct
76 Correct 438 ms 9052 KB Output is correct
77 Correct 340 ms 7116 KB Output is correct
78 Correct 363 ms 7672 KB Output is correct
79 Correct 328 ms 6744 KB Output is correct
80 Correct 1 ms 392 KB Output is correct
81 Correct 1 ms 340 KB Output is correct
82 Correct 2 ms 468 KB Output is correct
83 Correct 33 ms 1244 KB Output is correct
84 Correct 57 ms 1948 KB Output is correct
85 Correct 15 ms 988 KB Output is correct
86 Correct 1 ms 340 KB Output is correct
87 Correct 68 ms 2032 KB Output is correct
88 Correct 1 ms 340 KB Output is correct
89 Correct 1 ms 340 KB Output is correct
90 Correct 1 ms 340 KB Output is correct
91 Correct 25 ms 1464 KB Output is correct
92 Correct 123 ms 4804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 392 KB Output is correct
8 Correct 0 ms 396 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 392 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 428 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 396 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 396 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 ms 408 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 392 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 4 ms 532 KB Output is correct
51 Correct 3 ms 468 KB Output is correct
52 Correct 3 ms 468 KB Output is correct
53 Correct 3 ms 492 KB Output is correct
54 Correct 2 ms 468 KB Output is correct
55 Correct 4 ms 468 KB Output is correct
56 Correct 4 ms 520 KB Output is correct
57 Correct 4 ms 468 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 2 ms 452 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 0 ms 340 KB Output is correct
65 Correct 3 ms 388 KB Output is correct
66 Correct 0 ms 340 KB Output is correct
67 Correct 0 ms 340 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 2 ms 468 KB Output is correct
71 Correct 366 ms 7860 KB Output is correct
72 Correct 273 ms 6796 KB Output is correct
73 Correct 275 ms 6288 KB Output is correct
74 Correct 207 ms 5188 KB Output is correct
75 Correct 229 ms 5304 KB Output is correct
76 Correct 438 ms 9052 KB Output is correct
77 Correct 340 ms 7116 KB Output is correct
78 Correct 363 ms 7672 KB Output is correct
79 Correct 328 ms 6744 KB Output is correct
80 Correct 1 ms 392 KB Output is correct
81 Correct 1 ms 340 KB Output is correct
82 Correct 2 ms 468 KB Output is correct
83 Correct 33 ms 1244 KB Output is correct
84 Correct 57 ms 1948 KB Output is correct
85 Correct 15 ms 988 KB Output is correct
86 Correct 1 ms 340 KB Output is correct
87 Correct 68 ms 2032 KB Output is correct
88 Correct 1 ms 340 KB Output is correct
89 Correct 1 ms 340 KB Output is correct
90 Correct 1 ms 340 KB Output is correct
91 Correct 25 ms 1464 KB Output is correct
92 Correct 123 ms 4804 KB Output is correct
93 Correct 1698 ms 28928 KB Output is correct
94 Correct 1224 ms 23968 KB Output is correct
95 Correct 1330 ms 24080 KB Output is correct
96 Correct 1066 ms 19884 KB Output is correct
97 Correct 855 ms 15944 KB Output is correct
98 Correct 1753 ms 29556 KB Output is correct
99 Correct 1990 ms 31212 KB Output is correct
100 Correct 1771 ms 28844 KB Output is correct
101 Correct 1593 ms 24632 KB Output is correct
102 Correct 1266 ms 21644 KB Output is correct
103 Correct 1321 ms 23372 KB Output is correct
104 Correct 1 ms 388 KB Output is correct
105 Correct 1 ms 396 KB Output is correct
106 Correct 4 ms 468 KB Output is correct
107 Correct 97 ms 2912 KB Output is correct
108 Correct 329 ms 7384 KB Output is correct
109 Correct 34 ms 1620 KB Output is correct
110 Correct 1 ms 340 KB Output is correct
111 Correct 178 ms 4464 KB Output is correct
112 Correct 1 ms 392 KB Output is correct
113 Correct 1 ms 340 KB Output is correct
114 Correct 8 ms 980 KB Output is correct
115 Correct 1 ms 340 KB Output is correct
116 Correct 14 ms 1124 KB Output is correct
117 Correct 563 ms 14744 KB Output is correct