Submission #169775

# Submission time Handle Problem Language Result Execution time Memory
169775 2019-12-22T20:30:14 Z super_j6 Bootfall (IZhO17_bootfall) C++14
28 / 100
1000 ms 13144 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
using namespace std;
#define endl '\n'
#define pi pair<int, int>
 
const int maxn = 500, m = 250001;
int n;
int a[maxn];
map<int, int, greater<int>> dp;
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(auto it = dp.begin(); it != dp.end();){
			int j = it->first;
			it++;
			dp[j + a[i]] += dp[j];
		}
	}
	
	if(s % 2 || !dp[s / 2]){
		cout << 0 << endl;
		cout << endl;
		return 0;
	}
	
	for(int i = 1; i < m; i++) cur.insert(i);
	
	for(int i = 0; i < n; i++){
		for(auto it = prev(dp.end()); it != dp.begin();){
			int j = it->first;
			it--;
			if(!dp[j]) dp.erase(j);
			else 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.find((s - a[i] + x) / 2) == dp.end()) cur.erase(x);
		}
		
		for(auto it = dp.begin(); it != dp.end();){
			int j = it->first;
			it++;
			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:71:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 1; i < ans.size(); i++) cout << " " << ans[i];
                  ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 106 ms 12212 KB Output is correct
2 Correct 108 ms 12024 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 106 ms 12076 KB Output is correct
5 Correct 118 ms 12152 KB Output is correct
6 Correct 109 ms 12124 KB Output is correct
7 Correct 106 ms 12140 KB Output is correct
8 Correct 113 ms 12024 KB Output is correct
9 Correct 112 ms 12024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 106 ms 12212 KB Output is correct
2 Correct 108 ms 12024 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 106 ms 12076 KB Output is correct
5 Correct 118 ms 12152 KB Output is correct
6 Correct 109 ms 12124 KB Output is correct
7 Correct 106 ms 12140 KB Output is correct
8 Correct 113 ms 12024 KB Output is correct
9 Correct 112 ms 12024 KB Output is correct
10 Correct 109 ms 12024 KB Output is correct
11 Correct 118 ms 12132 KB Output is correct
12 Correct 115 ms 12152 KB Output is correct
13 Correct 112 ms 12152 KB Output is correct
14 Correct 118 ms 12028 KB Output is correct
15 Correct 114 ms 12048 KB Output is correct
16 Correct 116 ms 12140 KB Output is correct
17 Correct 114 ms 12152 KB Output is correct
18 Correct 114 ms 12188 KB Output is correct
19 Correct 120 ms 12280 KB Output is correct
20 Correct 110 ms 12152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 106 ms 12212 KB Output is correct
2 Correct 108 ms 12024 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 106 ms 12076 KB Output is correct
5 Correct 118 ms 12152 KB Output is correct
6 Correct 109 ms 12124 KB Output is correct
7 Correct 106 ms 12140 KB Output is correct
8 Correct 113 ms 12024 KB Output is correct
9 Correct 112 ms 12024 KB Output is correct
10 Correct 109 ms 12024 KB Output is correct
11 Correct 118 ms 12132 KB Output is correct
12 Correct 115 ms 12152 KB Output is correct
13 Correct 112 ms 12152 KB Output is correct
14 Correct 118 ms 12028 KB Output is correct
15 Correct 114 ms 12048 KB Output is correct
16 Correct 116 ms 12140 KB Output is correct
17 Correct 114 ms 12152 KB Output is correct
18 Correct 114 ms 12188 KB Output is correct
19 Correct 120 ms 12280 KB Output is correct
20 Correct 110 ms 12152 KB Output is correct
21 Correct 209 ms 12280 KB Output is correct
22 Correct 230 ms 12284 KB Output is correct
23 Correct 167 ms 12152 KB Output is correct
24 Correct 319 ms 12284 KB Output is correct
25 Correct 416 ms 12536 KB Output is correct
26 Correct 462 ms 12400 KB Output is correct
27 Correct 302 ms 12284 KB Output is correct
28 Correct 275 ms 12416 KB Output is correct
29 Correct 313 ms 12408 KB Output is correct
30 Correct 344 ms 12280 KB Output is correct
31 Correct 464 ms 12664 KB Output is correct
32 Correct 347 ms 12452 KB Output is correct
33 Correct 115 ms 12052 KB Output is correct
34 Correct 113 ms 12208 KB Output is correct
35 Correct 278 ms 12396 KB Output is correct
36 Correct 336 ms 12392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 106 ms 12212 KB Output is correct
2 Correct 108 ms 12024 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 106 ms 12076 KB Output is correct
5 Correct 118 ms 12152 KB Output is correct
6 Correct 109 ms 12124 KB Output is correct
7 Correct 106 ms 12140 KB Output is correct
8 Correct 113 ms 12024 KB Output is correct
9 Correct 112 ms 12024 KB Output is correct
10 Correct 109 ms 12024 KB Output is correct
11 Correct 118 ms 12132 KB Output is correct
12 Correct 115 ms 12152 KB Output is correct
13 Correct 112 ms 12152 KB Output is correct
14 Correct 118 ms 12028 KB Output is correct
15 Correct 114 ms 12048 KB Output is correct
16 Correct 116 ms 12140 KB Output is correct
17 Correct 114 ms 12152 KB Output is correct
18 Correct 114 ms 12188 KB Output is correct
19 Correct 120 ms 12280 KB Output is correct
20 Correct 110 ms 12152 KB Output is correct
21 Correct 209 ms 12280 KB Output is correct
22 Correct 230 ms 12284 KB Output is correct
23 Correct 167 ms 12152 KB Output is correct
24 Correct 319 ms 12284 KB Output is correct
25 Correct 416 ms 12536 KB Output is correct
26 Correct 462 ms 12400 KB Output is correct
27 Correct 302 ms 12284 KB Output is correct
28 Correct 275 ms 12416 KB Output is correct
29 Correct 313 ms 12408 KB Output is correct
30 Correct 344 ms 12280 KB Output is correct
31 Correct 464 ms 12664 KB Output is correct
32 Correct 347 ms 12452 KB Output is correct
33 Correct 115 ms 12052 KB Output is correct
34 Correct 113 ms 12208 KB Output is correct
35 Correct 278 ms 12396 KB Output is correct
36 Correct 336 ms 12392 KB Output is correct
37 Execution timed out 1080 ms 13144 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 106 ms 12212 KB Output is correct
2 Correct 108 ms 12024 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 106 ms 12076 KB Output is correct
5 Correct 118 ms 12152 KB Output is correct
6 Correct 109 ms 12124 KB Output is correct
7 Correct 106 ms 12140 KB Output is correct
8 Correct 113 ms 12024 KB Output is correct
9 Correct 112 ms 12024 KB Output is correct
10 Correct 109 ms 12024 KB Output is correct
11 Correct 118 ms 12132 KB Output is correct
12 Correct 115 ms 12152 KB Output is correct
13 Correct 112 ms 12152 KB Output is correct
14 Correct 118 ms 12028 KB Output is correct
15 Correct 114 ms 12048 KB Output is correct
16 Correct 116 ms 12140 KB Output is correct
17 Correct 114 ms 12152 KB Output is correct
18 Correct 114 ms 12188 KB Output is correct
19 Correct 120 ms 12280 KB Output is correct
20 Correct 110 ms 12152 KB Output is correct
21 Correct 209 ms 12280 KB Output is correct
22 Correct 230 ms 12284 KB Output is correct
23 Correct 167 ms 12152 KB Output is correct
24 Correct 319 ms 12284 KB Output is correct
25 Correct 416 ms 12536 KB Output is correct
26 Correct 462 ms 12400 KB Output is correct
27 Correct 302 ms 12284 KB Output is correct
28 Correct 275 ms 12416 KB Output is correct
29 Correct 313 ms 12408 KB Output is correct
30 Correct 344 ms 12280 KB Output is correct
31 Correct 464 ms 12664 KB Output is correct
32 Correct 347 ms 12452 KB Output is correct
33 Correct 115 ms 12052 KB Output is correct
34 Correct 113 ms 12208 KB Output is correct
35 Correct 278 ms 12396 KB Output is correct
36 Correct 336 ms 12392 KB Output is correct
37 Execution timed out 1080 ms 13144 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 106 ms 12212 KB Output is correct
2 Correct 108 ms 12024 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 106 ms 12076 KB Output is correct
5 Correct 118 ms 12152 KB Output is correct
6 Correct 109 ms 12124 KB Output is correct
7 Correct 106 ms 12140 KB Output is correct
8 Correct 113 ms 12024 KB Output is correct
9 Correct 112 ms 12024 KB Output is correct
10 Correct 109 ms 12024 KB Output is correct
11 Correct 118 ms 12132 KB Output is correct
12 Correct 115 ms 12152 KB Output is correct
13 Correct 112 ms 12152 KB Output is correct
14 Correct 118 ms 12028 KB Output is correct
15 Correct 114 ms 12048 KB Output is correct
16 Correct 116 ms 12140 KB Output is correct
17 Correct 114 ms 12152 KB Output is correct
18 Correct 114 ms 12188 KB Output is correct
19 Correct 120 ms 12280 KB Output is correct
20 Correct 110 ms 12152 KB Output is correct
21 Correct 209 ms 12280 KB Output is correct
22 Correct 230 ms 12284 KB Output is correct
23 Correct 167 ms 12152 KB Output is correct
24 Correct 319 ms 12284 KB Output is correct
25 Correct 416 ms 12536 KB Output is correct
26 Correct 462 ms 12400 KB Output is correct
27 Correct 302 ms 12284 KB Output is correct
28 Correct 275 ms 12416 KB Output is correct
29 Correct 313 ms 12408 KB Output is correct
30 Correct 344 ms 12280 KB Output is correct
31 Correct 464 ms 12664 KB Output is correct
32 Correct 347 ms 12452 KB Output is correct
33 Correct 115 ms 12052 KB Output is correct
34 Correct 113 ms 12208 KB Output is correct
35 Correct 278 ms 12396 KB Output is correct
36 Correct 336 ms 12392 KB Output is correct
37 Execution timed out 1080 ms 13144 KB Time limit exceeded
38 Halted 0 ms 0 KB -