Submission #35047

# Submission time Handle Problem Language Result Execution time Memory
35047 2017-11-17T19:51:42 Z model_code Bootfall (IZhO17_bootfall) C++11
65 / 100
1000 ms 17928 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <bitset>
#define f first
#define s second
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define vi vector <int>
#define ld long double
#define pii pair<int, int>
#define y1 sda
using namespace std;    
const int N = 502, mod = int(1e9)  + 7; 

int n,a[N];

int s;

bitset <N*N> dp[N];

vector <int> ans;
bool used[N];

int main () {
	scanf("%d",&n);
	bool odd = 0, even = 0;
	for(int i = 1; i <= n; i++){
		scanf("%d",&a[i]);
		s += a[i];
		if(a[i] & 1) odd = 1;
		else even = 1;
	}
	if(odd && even){
		printf("0");
		return 0;
	}
	dp[0][0] = 1;
	for(int i = 1; i <= n; i++){
		dp[0] = (dp[0] | (dp[0] << a[i]));
	}
	if((s & 1) || dp[0][s >> 1] == 0){
		printf("0");
		return 0;
	}
	for(int i = 1; i <= n; i++){
		if(used[a[i]]) continue;
		used[a[i]] = 1;
		dp[a[i]][0] = 1;
		for(int j = 1; j <= n; j++) if(i != j){
			dp[a[i]] |= (dp[a[i]] << a[j]);
		}
	}
	for(int x = 1; x <= s; x++){
		bool ok = 1;
		for(int i = 1; i <= n; i++){
			if((s - a[i] + x) & 1){
				ok = 0;
				break;
			}
			if(dp[a[i]][(s - a[i] + x) >> 1] == 0){
				ok = 0;
				break;
			}
		}
		if(ok){
			ans.pb(x);
		}
	}
	printf("%d\n", int(ans.size()));
	for(int i = 0; i < ans.size(); i++){
		printf("%d ", ans[i]);
	}

return 0;
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:84:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < ans.size(); i++){
                   ^
bootfall.cpp:39:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
bootfall.cpp:42:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a[i]);
                    ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 17460 KB Output is correct
2 Correct 0 ms 17460 KB Output is correct
3 Correct 0 ms 17460 KB Output is correct
4 Correct 0 ms 17460 KB Output is correct
5 Correct 0 ms 17460 KB Output is correct
6 Correct 0 ms 17460 KB Output is correct
7 Correct 0 ms 17460 KB Output is correct
8 Correct 0 ms 17460 KB Output is correct
9 Correct 0 ms 17460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 17460 KB Output is correct
2 Correct 0 ms 17460 KB Output is correct
3 Correct 0 ms 17460 KB Output is correct
4 Correct 0 ms 17460 KB Output is correct
5 Correct 0 ms 17460 KB Output is correct
6 Correct 0 ms 17460 KB Output is correct
7 Correct 0 ms 17460 KB Output is correct
8 Correct 0 ms 17460 KB Output is correct
9 Correct 0 ms 17460 KB Output is correct
10 Correct 0 ms 17460 KB Output is correct
11 Correct 3 ms 17460 KB Output is correct
12 Correct 3 ms 17460 KB Output is correct
13 Correct 0 ms 17460 KB Output is correct
14 Correct 3 ms 17460 KB Output is correct
15 Correct 3 ms 17460 KB Output is correct
16 Correct 3 ms 17460 KB Output is correct
17 Correct 3 ms 17460 KB Output is correct
18 Correct 3 ms 17460 KB Output is correct
19 Correct 0 ms 17460 KB Output is correct
20 Correct 0 ms 17460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 17460 KB Output is correct
2 Correct 0 ms 17460 KB Output is correct
3 Correct 0 ms 17460 KB Output is correct
4 Correct 0 ms 17460 KB Output is correct
5 Correct 0 ms 17460 KB Output is correct
6 Correct 0 ms 17460 KB Output is correct
7 Correct 0 ms 17460 KB Output is correct
8 Correct 0 ms 17460 KB Output is correct
9 Correct 0 ms 17460 KB Output is correct
10 Correct 0 ms 17460 KB Output is correct
11 Correct 3 ms 17460 KB Output is correct
12 Correct 3 ms 17460 KB Output is correct
13 Correct 0 ms 17460 KB Output is correct
14 Correct 3 ms 17460 KB Output is correct
15 Correct 3 ms 17460 KB Output is correct
16 Correct 3 ms 17460 KB Output is correct
17 Correct 3 ms 17460 KB Output is correct
18 Correct 3 ms 17460 KB Output is correct
19 Correct 0 ms 17460 KB Output is correct
20 Correct 0 ms 17460 KB Output is correct
21 Correct 36 ms 17460 KB Output is correct
22 Correct 43 ms 17460 KB Output is correct
23 Correct 23 ms 17460 KB Output is correct
24 Correct 63 ms 17460 KB Output is correct
25 Correct 9 ms 17460 KB Output is correct
26 Correct 9 ms 17460 KB Output is correct
27 Correct 9 ms 17460 KB Output is correct
28 Correct 6 ms 17460 KB Output is correct
29 Correct 6 ms 17460 KB Output is correct
30 Correct 0 ms 17460 KB Output is correct
31 Correct 39 ms 17460 KB Output is correct
32 Correct 66 ms 17460 KB Output is correct
33 Correct 3 ms 17460 KB Output is correct
34 Correct 3 ms 17460 KB Output is correct
35 Correct 6 ms 17460 KB Output is correct
36 Correct 76 ms 17460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 17460 KB Output is correct
2 Correct 0 ms 17460 KB Output is correct
3 Correct 0 ms 17460 KB Output is correct
4 Correct 0 ms 17460 KB Output is correct
5 Correct 0 ms 17460 KB Output is correct
6 Correct 0 ms 17460 KB Output is correct
7 Correct 0 ms 17460 KB Output is correct
8 Correct 0 ms 17460 KB Output is correct
9 Correct 0 ms 17460 KB Output is correct
10 Correct 0 ms 17460 KB Output is correct
11 Correct 3 ms 17460 KB Output is correct
12 Correct 3 ms 17460 KB Output is correct
13 Correct 0 ms 17460 KB Output is correct
14 Correct 3 ms 17460 KB Output is correct
15 Correct 3 ms 17460 KB Output is correct
16 Correct 3 ms 17460 KB Output is correct
17 Correct 3 ms 17460 KB Output is correct
18 Correct 3 ms 17460 KB Output is correct
19 Correct 0 ms 17460 KB Output is correct
20 Correct 0 ms 17460 KB Output is correct
21 Correct 36 ms 17460 KB Output is correct
22 Correct 43 ms 17460 KB Output is correct
23 Correct 23 ms 17460 KB Output is correct
24 Correct 63 ms 17460 KB Output is correct
25 Correct 9 ms 17460 KB Output is correct
26 Correct 9 ms 17460 KB Output is correct
27 Correct 9 ms 17460 KB Output is correct
28 Correct 6 ms 17460 KB Output is correct
29 Correct 6 ms 17460 KB Output is correct
30 Correct 0 ms 17460 KB Output is correct
31 Correct 39 ms 17460 KB Output is correct
32 Correct 66 ms 17460 KB Output is correct
33 Correct 3 ms 17460 KB Output is correct
34 Correct 3 ms 17460 KB Output is correct
35 Correct 6 ms 17460 KB Output is correct
36 Correct 76 ms 17460 KB Output is correct
37 Correct 159 ms 17600 KB Output is correct
38 Correct 163 ms 17600 KB Output is correct
39 Correct 9 ms 17460 KB Output is correct
40 Correct 549 ms 17600 KB Output is correct
41 Correct 9 ms 17460 KB Output is correct
42 Correct 419 ms 17600 KB Output is correct
43 Correct 116 ms 17732 KB Output is correct
44 Correct 116 ms 17732 KB Output is correct
45 Correct 113 ms 17732 KB Output is correct
46 Correct 543 ms 17460 KB Output is correct
47 Correct 449 ms 17600 KB Output is correct
48 Correct 36 ms 17732 KB Output is correct
49 Correct 19 ms 17600 KB Output is correct
50 Correct 476 ms 17600 KB Output is correct
51 Correct 0 ms 17460 KB Output is correct
52 Correct 63 ms 17732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 17460 KB Output is correct
2 Correct 0 ms 17460 KB Output is correct
3 Correct 0 ms 17460 KB Output is correct
4 Correct 0 ms 17460 KB Output is correct
5 Correct 0 ms 17460 KB Output is correct
6 Correct 0 ms 17460 KB Output is correct
7 Correct 0 ms 17460 KB Output is correct
8 Correct 0 ms 17460 KB Output is correct
9 Correct 0 ms 17460 KB Output is correct
10 Correct 0 ms 17460 KB Output is correct
11 Correct 3 ms 17460 KB Output is correct
12 Correct 3 ms 17460 KB Output is correct
13 Correct 0 ms 17460 KB Output is correct
14 Correct 3 ms 17460 KB Output is correct
15 Correct 3 ms 17460 KB Output is correct
16 Correct 3 ms 17460 KB Output is correct
17 Correct 3 ms 17460 KB Output is correct
18 Correct 3 ms 17460 KB Output is correct
19 Correct 0 ms 17460 KB Output is correct
20 Correct 0 ms 17460 KB Output is correct
21 Correct 36 ms 17460 KB Output is correct
22 Correct 43 ms 17460 KB Output is correct
23 Correct 23 ms 17460 KB Output is correct
24 Correct 63 ms 17460 KB Output is correct
25 Correct 9 ms 17460 KB Output is correct
26 Correct 9 ms 17460 KB Output is correct
27 Correct 9 ms 17460 KB Output is correct
28 Correct 6 ms 17460 KB Output is correct
29 Correct 6 ms 17460 KB Output is correct
30 Correct 0 ms 17460 KB Output is correct
31 Correct 39 ms 17460 KB Output is correct
32 Correct 66 ms 17460 KB Output is correct
33 Correct 3 ms 17460 KB Output is correct
34 Correct 3 ms 17460 KB Output is correct
35 Correct 6 ms 17460 KB Output is correct
36 Correct 76 ms 17460 KB Output is correct
37 Correct 159 ms 17600 KB Output is correct
38 Correct 163 ms 17600 KB Output is correct
39 Correct 9 ms 17460 KB Output is correct
40 Correct 549 ms 17600 KB Output is correct
41 Correct 9 ms 17460 KB Output is correct
42 Correct 419 ms 17600 KB Output is correct
43 Correct 116 ms 17732 KB Output is correct
44 Correct 116 ms 17732 KB Output is correct
45 Correct 113 ms 17732 KB Output is correct
46 Correct 543 ms 17460 KB Output is correct
47 Correct 449 ms 17600 KB Output is correct
48 Correct 36 ms 17732 KB Output is correct
49 Correct 19 ms 17600 KB Output is correct
50 Correct 476 ms 17600 KB Output is correct
51 Correct 0 ms 17460 KB Output is correct
52 Correct 63 ms 17732 KB Output is correct
53 Correct 539 ms 17732 KB Output is correct
54 Correct 659 ms 17732 KB Output is correct
55 Correct 123 ms 17928 KB Output is correct
56 Correct 643 ms 17732 KB Output is correct
57 Correct 139 ms 17928 KB Output is correct
58 Correct 969 ms 17732 KB Output is correct
59 Correct 613 ms 17928 KB Output is correct
60 Correct 0 ms 17460 KB Output is correct
61 Correct 566 ms 17928 KB Output is correct
62 Correct 276 ms 17928 KB Output is correct
63 Correct 169 ms 17928 KB Output is correct
64 Correct 159 ms 17928 KB Output is correct
65 Correct 43 ms 17460 KB Output is correct
66 Correct 169 ms 17600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 17460 KB Output is correct
2 Correct 0 ms 17460 KB Output is correct
3 Correct 0 ms 17460 KB Output is correct
4 Correct 0 ms 17460 KB Output is correct
5 Correct 0 ms 17460 KB Output is correct
6 Correct 0 ms 17460 KB Output is correct
7 Correct 0 ms 17460 KB Output is correct
8 Correct 0 ms 17460 KB Output is correct
9 Correct 0 ms 17460 KB Output is correct
10 Correct 0 ms 17460 KB Output is correct
11 Correct 3 ms 17460 KB Output is correct
12 Correct 3 ms 17460 KB Output is correct
13 Correct 0 ms 17460 KB Output is correct
14 Correct 3 ms 17460 KB Output is correct
15 Correct 3 ms 17460 KB Output is correct
16 Correct 3 ms 17460 KB Output is correct
17 Correct 3 ms 17460 KB Output is correct
18 Correct 3 ms 17460 KB Output is correct
19 Correct 0 ms 17460 KB Output is correct
20 Correct 0 ms 17460 KB Output is correct
21 Correct 36 ms 17460 KB Output is correct
22 Correct 43 ms 17460 KB Output is correct
23 Correct 23 ms 17460 KB Output is correct
24 Correct 63 ms 17460 KB Output is correct
25 Correct 9 ms 17460 KB Output is correct
26 Correct 9 ms 17460 KB Output is correct
27 Correct 9 ms 17460 KB Output is correct
28 Correct 6 ms 17460 KB Output is correct
29 Correct 6 ms 17460 KB Output is correct
30 Correct 0 ms 17460 KB Output is correct
31 Correct 39 ms 17460 KB Output is correct
32 Correct 66 ms 17460 KB Output is correct
33 Correct 3 ms 17460 KB Output is correct
34 Correct 3 ms 17460 KB Output is correct
35 Correct 6 ms 17460 KB Output is correct
36 Correct 76 ms 17460 KB Output is correct
37 Correct 159 ms 17600 KB Output is correct
38 Correct 163 ms 17600 KB Output is correct
39 Correct 9 ms 17460 KB Output is correct
40 Correct 549 ms 17600 KB Output is correct
41 Correct 9 ms 17460 KB Output is correct
42 Correct 419 ms 17600 KB Output is correct
43 Correct 116 ms 17732 KB Output is correct
44 Correct 116 ms 17732 KB Output is correct
45 Correct 113 ms 17732 KB Output is correct
46 Correct 543 ms 17460 KB Output is correct
47 Correct 449 ms 17600 KB Output is correct
48 Correct 36 ms 17732 KB Output is correct
49 Correct 19 ms 17600 KB Output is correct
50 Correct 476 ms 17600 KB Output is correct
51 Correct 0 ms 17460 KB Output is correct
52 Correct 63 ms 17732 KB Output is correct
53 Correct 539 ms 17732 KB Output is correct
54 Correct 659 ms 17732 KB Output is correct
55 Correct 123 ms 17928 KB Output is correct
56 Correct 643 ms 17732 KB Output is correct
57 Correct 139 ms 17928 KB Output is correct
58 Correct 969 ms 17732 KB Output is correct
59 Correct 613 ms 17928 KB Output is correct
60 Correct 0 ms 17460 KB Output is correct
61 Correct 566 ms 17928 KB Output is correct
62 Correct 276 ms 17928 KB Output is correct
63 Correct 169 ms 17928 KB Output is correct
64 Correct 159 ms 17928 KB Output is correct
65 Correct 43 ms 17460 KB Output is correct
66 Correct 169 ms 17600 KB Output is correct
67 Execution timed out 1000 ms 17928 KB Execution timed out
68 Halted 0 ms 0 KB -