답안 #169776

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
169776 2019-12-22T20:31:57 Z super_j6 Bootfall (IZhO17_bootfall) C++14
65 / 100
579 ms 34180 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;
#define endl '\n'
#define pi pair<int, int>

const int maxn = 500, m = 250001;
int n;
int a[maxn], dp[m];
set<int> cur;
int s;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n;
	
	dp[0] = 1;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		s += a[i];
		
		for(int j = m - a[i] - 1; j >= 0; j--){
			dp[j + a[i]] += dp[j];
		}
	}
	
	if(s % 2 || !dp[s / 2]){
		cout << 0 << endl;
		cout << endl;
		return 0;
	}
	
	for(int i = 1; i < 4 * m / 3; i++) cur.insert(i);
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m - a[i]; j++){
			dp[j + a[i]] -= dp[j];
		}
		
		for(auto it = cur.begin(); it != cur.end();){
			int x = *it;
			it++;
			if((s - a[i] + x) % 2 || !dp[(s - a[i] + x) / 2]) cur.erase(x);
		}
		
		for(int j = m - a[i] - 1; j >= 0; j--){
			dp[j + a[i]] += dp[j];
		}
	}
	
	vector<int> ans;
	for(auto it = cur.begin(); it != cur.end(); it++) ans.push_back(*it);
	
	cout << ans.size() << endl;
	if(!ans.empty()){
		cout << ans[0];
		for(int i = 1; i < ans.size(); i++) cout << " " << ans[i];
	}
	cout << endl;

	return 0;
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:62:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 1; i < ans.size(); i++) cout << " " << ans[i];
                  ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 143 ms 16956 KB Output is correct
2 Correct 154 ms 17016 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 145 ms 17116 KB Output is correct
5 Correct 153 ms 17016 KB Output is correct
6 Correct 145 ms 17016 KB Output is correct
7 Correct 144 ms 16980 KB Output is correct
8 Correct 150 ms 17016 KB Output is correct
9 Correct 151 ms 17052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 143 ms 16956 KB Output is correct
2 Correct 154 ms 17016 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 145 ms 17116 KB Output is correct
5 Correct 153 ms 17016 KB Output is correct
6 Correct 145 ms 17016 KB Output is correct
7 Correct 144 ms 16980 KB Output is correct
8 Correct 150 ms 17016 KB Output is correct
9 Correct 151 ms 17052 KB Output is correct
10 Correct 157 ms 17116 KB Output is correct
11 Correct 159 ms 16952 KB Output is correct
12 Correct 159 ms 16948 KB Output is correct
13 Correct 155 ms 17016 KB Output is correct
14 Correct 163 ms 17040 KB Output is correct
15 Correct 158 ms 17136 KB Output is correct
16 Correct 158 ms 17060 KB Output is correct
17 Correct 152 ms 17004 KB Output is correct
18 Correct 156 ms 17116 KB Output is correct
19 Correct 156 ms 16932 KB Output is correct
20 Correct 157 ms 17116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 143 ms 16956 KB Output is correct
2 Correct 154 ms 17016 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 145 ms 17116 KB Output is correct
5 Correct 153 ms 17016 KB Output is correct
6 Correct 145 ms 17016 KB Output is correct
7 Correct 144 ms 16980 KB Output is correct
8 Correct 150 ms 17016 KB Output is correct
9 Correct 151 ms 17052 KB Output is correct
10 Correct 157 ms 17116 KB Output is correct
11 Correct 159 ms 16952 KB Output is correct
12 Correct 159 ms 16948 KB Output is correct
13 Correct 155 ms 17016 KB Output is correct
14 Correct 163 ms 17040 KB Output is correct
15 Correct 158 ms 17136 KB Output is correct
16 Correct 158 ms 17060 KB Output is correct
17 Correct 152 ms 17004 KB Output is correct
18 Correct 156 ms 17116 KB Output is correct
19 Correct 156 ms 16932 KB Output is correct
20 Correct 157 ms 17116 KB Output is correct
21 Correct 183 ms 16888 KB Output is correct
22 Correct 188 ms 17052 KB Output is correct
23 Correct 178 ms 17096 KB Output is correct
24 Correct 216 ms 17004 KB Output is correct
25 Correct 202 ms 16888 KB Output is correct
26 Correct 211 ms 16968 KB Output is correct
27 Correct 242 ms 17020 KB Output is correct
28 Correct 206 ms 17016 KB Output is correct
29 Correct 205 ms 17144 KB Output is correct
30 Correct 202 ms 17176 KB Output is correct
31 Correct 208 ms 16952 KB Output is correct
32 Correct 211 ms 17016 KB Output is correct
33 Correct 195 ms 16932 KB Output is correct
34 Correct 193 ms 16924 KB Output is correct
35 Correct 200 ms 17052 KB Output is correct
36 Correct 205 ms 17120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 143 ms 16956 KB Output is correct
2 Correct 154 ms 17016 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 145 ms 17116 KB Output is correct
5 Correct 153 ms 17016 KB Output is correct
6 Correct 145 ms 17016 KB Output is correct
7 Correct 144 ms 16980 KB Output is correct
8 Correct 150 ms 17016 KB Output is correct
9 Correct 151 ms 17052 KB Output is correct
10 Correct 157 ms 17116 KB Output is correct
11 Correct 159 ms 16952 KB Output is correct
12 Correct 159 ms 16948 KB Output is correct
13 Correct 155 ms 17016 KB Output is correct
14 Correct 163 ms 17040 KB Output is correct
15 Correct 158 ms 17136 KB Output is correct
16 Correct 158 ms 17060 KB Output is correct
17 Correct 152 ms 17004 KB Output is correct
18 Correct 156 ms 17116 KB Output is correct
19 Correct 156 ms 16932 KB Output is correct
20 Correct 157 ms 17116 KB Output is correct
21 Correct 183 ms 16888 KB Output is correct
22 Correct 188 ms 17052 KB Output is correct
23 Correct 178 ms 17096 KB Output is correct
24 Correct 216 ms 17004 KB Output is correct
25 Correct 202 ms 16888 KB Output is correct
26 Correct 211 ms 16968 KB Output is correct
27 Correct 242 ms 17020 KB Output is correct
28 Correct 206 ms 17016 KB Output is correct
29 Correct 205 ms 17144 KB Output is correct
30 Correct 202 ms 17176 KB Output is correct
31 Correct 208 ms 16952 KB Output is correct
32 Correct 211 ms 17016 KB Output is correct
33 Correct 195 ms 16932 KB Output is correct
34 Correct 193 ms 16924 KB Output is correct
35 Correct 200 ms 17052 KB Output is correct
36 Correct 205 ms 17120 KB Output is correct
37 Correct 279 ms 17068 KB Output is correct
38 Correct 278 ms 16904 KB Output is correct
39 Correct 261 ms 17052 KB Output is correct
40 Correct 341 ms 17036 KB Output is correct
41 Correct 275 ms 17016 KB Output is correct
42 Correct 324 ms 17052 KB Output is correct
43 Correct 362 ms 17244 KB Output is correct
44 Correct 364 ms 17016 KB Output is correct
45 Correct 370 ms 17016 KB Output is correct
46 Correct 281 ms 17016 KB Output is correct
47 Correct 326 ms 16936 KB Output is correct
48 Correct 341 ms 16956 KB Output is correct
49 Correct 287 ms 16988 KB Output is correct
50 Correct 347 ms 17080 KB Output is correct
51 Correct 42 ms 1272 KB Output is correct
52 Correct 389 ms 17144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 143 ms 16956 KB Output is correct
2 Correct 154 ms 17016 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 145 ms 17116 KB Output is correct
5 Correct 153 ms 17016 KB Output is correct
6 Correct 145 ms 17016 KB Output is correct
7 Correct 144 ms 16980 KB Output is correct
8 Correct 150 ms 17016 KB Output is correct
9 Correct 151 ms 17052 KB Output is correct
10 Correct 157 ms 17116 KB Output is correct
11 Correct 159 ms 16952 KB Output is correct
12 Correct 159 ms 16948 KB Output is correct
13 Correct 155 ms 17016 KB Output is correct
14 Correct 163 ms 17040 KB Output is correct
15 Correct 158 ms 17136 KB Output is correct
16 Correct 158 ms 17060 KB Output is correct
17 Correct 152 ms 17004 KB Output is correct
18 Correct 156 ms 17116 KB Output is correct
19 Correct 156 ms 16932 KB Output is correct
20 Correct 157 ms 17116 KB Output is correct
21 Correct 183 ms 16888 KB Output is correct
22 Correct 188 ms 17052 KB Output is correct
23 Correct 178 ms 17096 KB Output is correct
24 Correct 216 ms 17004 KB Output is correct
25 Correct 202 ms 16888 KB Output is correct
26 Correct 211 ms 16968 KB Output is correct
27 Correct 242 ms 17020 KB Output is correct
28 Correct 206 ms 17016 KB Output is correct
29 Correct 205 ms 17144 KB Output is correct
30 Correct 202 ms 17176 KB Output is correct
31 Correct 208 ms 16952 KB Output is correct
32 Correct 211 ms 17016 KB Output is correct
33 Correct 195 ms 16932 KB Output is correct
34 Correct 193 ms 16924 KB Output is correct
35 Correct 200 ms 17052 KB Output is correct
36 Correct 205 ms 17120 KB Output is correct
37 Correct 279 ms 17068 KB Output is correct
38 Correct 278 ms 16904 KB Output is correct
39 Correct 261 ms 17052 KB Output is correct
40 Correct 341 ms 17036 KB Output is correct
41 Correct 275 ms 17016 KB Output is correct
42 Correct 324 ms 17052 KB Output is correct
43 Correct 362 ms 17244 KB Output is correct
44 Correct 364 ms 17016 KB Output is correct
45 Correct 370 ms 17016 KB Output is correct
46 Correct 281 ms 17016 KB Output is correct
47 Correct 326 ms 16936 KB Output is correct
48 Correct 341 ms 16956 KB Output is correct
49 Correct 287 ms 16988 KB Output is correct
50 Correct 347 ms 17080 KB Output is correct
51 Correct 42 ms 1272 KB Output is correct
52 Correct 389 ms 17144 KB Output is correct
53 Correct 391 ms 17012 KB Output is correct
54 Correct 455 ms 16944 KB Output is correct
55 Correct 561 ms 17016 KB Output is correct
56 Correct 425 ms 17112 KB Output is correct
57 Correct 579 ms 17016 KB Output is correct
58 Correct 469 ms 17144 KB Output is correct
59 Correct 521 ms 17016 KB Output is correct
60 Correct 58 ms 1272 KB Output is correct
61 Correct 539 ms 17092 KB Output is correct
62 Correct 526 ms 17052 KB Output is correct
63 Correct 534 ms 17016 KB Output is correct
64 Correct 521 ms 17144 KB Output is correct
65 Correct 305 ms 17008 KB Output is correct
66 Correct 334 ms 17144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 143 ms 16956 KB Output is correct
2 Correct 154 ms 17016 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 145 ms 17116 KB Output is correct
5 Correct 153 ms 17016 KB Output is correct
6 Correct 145 ms 17016 KB Output is correct
7 Correct 144 ms 16980 KB Output is correct
8 Correct 150 ms 17016 KB Output is correct
9 Correct 151 ms 17052 KB Output is correct
10 Correct 157 ms 17116 KB Output is correct
11 Correct 159 ms 16952 KB Output is correct
12 Correct 159 ms 16948 KB Output is correct
13 Correct 155 ms 17016 KB Output is correct
14 Correct 163 ms 17040 KB Output is correct
15 Correct 158 ms 17136 KB Output is correct
16 Correct 158 ms 17060 KB Output is correct
17 Correct 152 ms 17004 KB Output is correct
18 Correct 156 ms 17116 KB Output is correct
19 Correct 156 ms 16932 KB Output is correct
20 Correct 157 ms 17116 KB Output is correct
21 Correct 183 ms 16888 KB Output is correct
22 Correct 188 ms 17052 KB Output is correct
23 Correct 178 ms 17096 KB Output is correct
24 Correct 216 ms 17004 KB Output is correct
25 Correct 202 ms 16888 KB Output is correct
26 Correct 211 ms 16968 KB Output is correct
27 Correct 242 ms 17020 KB Output is correct
28 Correct 206 ms 17016 KB Output is correct
29 Correct 205 ms 17144 KB Output is correct
30 Correct 202 ms 17176 KB Output is correct
31 Correct 208 ms 16952 KB Output is correct
32 Correct 211 ms 17016 KB Output is correct
33 Correct 195 ms 16932 KB Output is correct
34 Correct 193 ms 16924 KB Output is correct
35 Correct 200 ms 17052 KB Output is correct
36 Correct 205 ms 17120 KB Output is correct
37 Correct 279 ms 17068 KB Output is correct
38 Correct 278 ms 16904 KB Output is correct
39 Correct 261 ms 17052 KB Output is correct
40 Correct 341 ms 17036 KB Output is correct
41 Correct 275 ms 17016 KB Output is correct
42 Correct 324 ms 17052 KB Output is correct
43 Correct 362 ms 17244 KB Output is correct
44 Correct 364 ms 17016 KB Output is correct
45 Correct 370 ms 17016 KB Output is correct
46 Correct 281 ms 17016 KB Output is correct
47 Correct 326 ms 16936 KB Output is correct
48 Correct 341 ms 16956 KB Output is correct
49 Correct 287 ms 16988 KB Output is correct
50 Correct 347 ms 17080 KB Output is correct
51 Correct 42 ms 1272 KB Output is correct
52 Correct 389 ms 17144 KB Output is correct
53 Correct 391 ms 17012 KB Output is correct
54 Correct 455 ms 16944 KB Output is correct
55 Correct 561 ms 17016 KB Output is correct
56 Correct 425 ms 17112 KB Output is correct
57 Correct 579 ms 17016 KB Output is correct
58 Correct 469 ms 17144 KB Output is correct
59 Correct 521 ms 17016 KB Output is correct
60 Correct 58 ms 1272 KB Output is correct
61 Correct 539 ms 17092 KB Output is correct
62 Correct 526 ms 17052 KB Output is correct
63 Correct 534 ms 17016 KB Output is correct
64 Correct 521 ms 17144 KB Output is correct
65 Correct 305 ms 17008 KB Output is correct
66 Correct 334 ms 17144 KB Output is correct
67 Correct 571 ms 17116 KB Output is correct
68 Correct 81 ms 1272 KB Output is correct
69 Runtime error 239 ms 34180 KB Execution killed with signal 11 (could be triggered by violating memory limits)
70 Halted 0 ms 0 KB -