답안 #826039

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
826039 2023-08-15T10:03:32 Z dxz05 Toys (CEOI18_toy) C++17
100 / 100
4151 ms 86476 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){
			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){
			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]);
			}
		}
	}
	
	cout << dp[m - 1].size() << endl;
	
	for (auto [l, r] : dp[m - 1]){
		while (l <= r){
			cout << l << ' ';
			l++;
		}
	}
	cout << endl;
	
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 392 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 0 ms 340 KB Output is correct
7 Correct 1 ms 396 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 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 1 ms 340 KB Output is correct
14 Correct 1 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 1 ms 340 KB Output is correct
18 Correct 1 ms 392 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 392 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 0 ms 340 KB Output is correct
7 Correct 1 ms 396 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 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 1 ms 340 KB Output is correct
14 Correct 1 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 1 ms 340 KB Output is correct
18 Correct 1 ms 392 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 392 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 388 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 388 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 2 ms 340 KB Output is correct
38 Correct 1 ms 392 KB Output is correct
39 Correct 0 ms 392 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 392 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 388 KB Output is correct
47 Correct 1 ms 396 KB Output is correct
48 Correct 1 ms 388 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 392 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 0 ms 340 KB Output is correct
7 Correct 1 ms 396 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 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 1 ms 340 KB Output is correct
14 Correct 1 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 1 ms 340 KB Output is correct
18 Correct 1 ms 392 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 392 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 388 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 388 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 2 ms 340 KB Output is correct
38 Correct 1 ms 392 KB Output is correct
39 Correct 0 ms 392 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 392 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 388 KB Output is correct
47 Correct 1 ms 396 KB Output is correct
48 Correct 1 ms 388 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 5 ms 596 KB Output is correct
51 Correct 5 ms 524 KB Output is correct
52 Correct 5 ms 596 KB Output is correct
53 Correct 5 ms 612 KB Output is correct
54 Correct 2 ms 468 KB Output is correct
55 Correct 6 ms 768 KB Output is correct
56 Correct 6 ms 620 KB Output is correct
57 Correct 5 ms 596 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 0 ms 392 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 3 ms 520 KB Output is correct
62 Correct 2 ms 468 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 3 ms 516 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 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 392 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 0 ms 340 KB Output is correct
7 Correct 1 ms 396 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 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 1 ms 340 KB Output is correct
14 Correct 1 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 1 ms 340 KB Output is correct
18 Correct 1 ms 392 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 392 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 388 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 388 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 2 ms 340 KB Output is correct
38 Correct 1 ms 392 KB Output is correct
39 Correct 0 ms 392 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 392 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 388 KB Output is correct
47 Correct 1 ms 396 KB Output is correct
48 Correct 1 ms 388 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 5 ms 596 KB Output is correct
51 Correct 5 ms 524 KB Output is correct
52 Correct 5 ms 596 KB Output is correct
53 Correct 5 ms 612 KB Output is correct
54 Correct 2 ms 468 KB Output is correct
55 Correct 6 ms 768 KB Output is correct
56 Correct 6 ms 620 KB Output is correct
57 Correct 5 ms 596 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 0 ms 392 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 3 ms 520 KB Output is correct
62 Correct 2 ms 468 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 3 ms 516 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 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 607 ms 18520 KB Output is correct
72 Correct 422 ms 13968 KB Output is correct
73 Correct 630 ms 16496 KB Output is correct
74 Correct 330 ms 11120 KB Output is correct
75 Correct 375 ms 11808 KB Output is correct
76 Correct 971 ms 24856 KB Output is correct
77 Correct 911 ms 21912 KB Output is correct
78 Correct 815 ms 20632 KB Output is correct
79 Correct 748 ms 20056 KB Output is correct
80 Correct 1 ms 392 KB Output is correct
81 Correct 1 ms 340 KB Output is correct
82 Correct 5 ms 644 KB Output is correct
83 Correct 94 ms 3660 KB Output is correct
84 Correct 103 ms 4344 KB Output is correct
85 Correct 24 ms 1540 KB Output is correct
86 Correct 1 ms 340 KB Output is correct
87 Correct 115 ms 4968 KB Output is correct
88 Correct 1 ms 392 KB Output is correct
89 Correct 1 ms 340 KB Output is correct
90 Correct 1 ms 396 KB Output is correct
91 Correct 29 ms 2124 KB Output is correct
92 Correct 141 ms 6476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 392 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 0 ms 340 KB Output is correct
7 Correct 1 ms 396 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 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 1 ms 340 KB Output is correct
14 Correct 1 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 1 ms 340 KB Output is correct
18 Correct 1 ms 392 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 392 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 388 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 388 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 2 ms 340 KB Output is correct
38 Correct 1 ms 392 KB Output is correct
39 Correct 0 ms 392 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 392 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 388 KB Output is correct
47 Correct 1 ms 396 KB Output is correct
48 Correct 1 ms 388 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 5 ms 596 KB Output is correct
51 Correct 5 ms 524 KB Output is correct
52 Correct 5 ms 596 KB Output is correct
53 Correct 5 ms 612 KB Output is correct
54 Correct 2 ms 468 KB Output is correct
55 Correct 6 ms 768 KB Output is correct
56 Correct 6 ms 620 KB Output is correct
57 Correct 5 ms 596 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 0 ms 392 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 3 ms 520 KB Output is correct
62 Correct 2 ms 468 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 3 ms 516 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 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 607 ms 18520 KB Output is correct
72 Correct 422 ms 13968 KB Output is correct
73 Correct 630 ms 16496 KB Output is correct
74 Correct 330 ms 11120 KB Output is correct
75 Correct 375 ms 11808 KB Output is correct
76 Correct 971 ms 24856 KB Output is correct
77 Correct 911 ms 21912 KB Output is correct
78 Correct 815 ms 20632 KB Output is correct
79 Correct 748 ms 20056 KB Output is correct
80 Correct 1 ms 392 KB Output is correct
81 Correct 1 ms 340 KB Output is correct
82 Correct 5 ms 644 KB Output is correct
83 Correct 94 ms 3660 KB Output is correct
84 Correct 103 ms 4344 KB Output is correct
85 Correct 24 ms 1540 KB Output is correct
86 Correct 1 ms 340 KB Output is correct
87 Correct 115 ms 4968 KB Output is correct
88 Correct 1 ms 392 KB Output is correct
89 Correct 1 ms 340 KB Output is correct
90 Correct 1 ms 396 KB Output is correct
91 Correct 29 ms 2124 KB Output is correct
92 Correct 141 ms 6476 KB Output is correct
93 Correct 3739 ms 77256 KB Output is correct
94 Correct 2047 ms 52028 KB Output is correct
95 Correct 2330 ms 54616 KB Output is correct
96 Correct 2041 ms 48632 KB Output is correct
97 Correct 1956 ms 44316 KB Output is correct
98 Correct 4070 ms 85176 KB Output is correct
99 Correct 4151 ms 86476 KB Output is correct
100 Correct 3979 ms 83188 KB Output is correct
101 Correct 3792 ms 77108 KB Output is correct
102 Correct 3372 ms 69280 KB Output is correct
103 Correct 2559 ms 62208 KB Output is correct
104 Correct 1 ms 340 KB Output is correct
105 Correct 1 ms 392 KB Output is correct
106 Correct 9 ms 944 KB Output is correct
107 Correct 265 ms 9540 KB Output is correct
108 Correct 697 ms 20352 KB Output is correct
109 Correct 55 ms 3216 KB Output is correct
110 Correct 1 ms 340 KB Output is correct
111 Correct 326 ms 12092 KB Output is correct
112 Correct 1 ms 340 KB Output is correct
113 Correct 1 ms 340 KB Output is correct
114 Correct 8 ms 896 KB Output is correct
115 Correct 1 ms 340 KB Output is correct
116 Correct 24 ms 1684 KB Output is correct
117 Correct 669 ms 24456 KB Output is correct