Submission #37471

# Submission time Handle Problem Language Result Execution time Memory
37471 2017-12-25T16:06:14 Z HardNut Bootfall (IZhO17_bootfall) C++14
100 / 100
693 ms 4840 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, mod1 = int(1e9)  + 7, mod2 = int(1e9) + 9;

int n,a[N];

int s, sum;

int dp[N * N];
int f[N * N];
vi ans;
bool used[N];

inline void add(int x){
	for(int j = sum; j >= 0; j--){
		dp[j + x] += dp[j];
		if(dp[j + x] >= mod1) dp[j + x] -= mod1;
	}
	sum += x;
}

inline void del(int x){
	sum -= x;
	for(int j = 0; j <= sum; j++){
		dp[j + x] += (mod1 - dp[j]);
		if(dp[j + x] >= mod1) dp[j + x] -= mod1;
	}
}

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] = 1;
	for(int i = 1; i <= n; i++){
		add(a[i]);
	}
	if((s & 1) || !dp[s>>1]){
		printf("0");
		return 0;
	}
	for(int i = 1; i <= n; i++){
		if(used[a[i]]) continue;
		used[a[i]] = 1;
		del(a[i]);
		for(int j = 1; j <= s; j++){
			int cur = s - a[i] + j;
			if((cur & 1) || !dp[cur>>1]){
				f[j] = 1;
			}
		}
		add(a[i]);
	}
	for(int x = 1; x <= s; x++){
		if(!f[x]) 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:91:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < ans.size(); i++){
                   ^
bootfall.cpp:55:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
bootfall.cpp:58: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 3988 KB Output is correct
2 Correct 0 ms 3988 KB Output is correct
3 Correct 0 ms 3988 KB Output is correct
4 Correct 0 ms 3988 KB Output is correct
5 Correct 0 ms 3988 KB Output is correct
6 Correct 0 ms 3988 KB Output is correct
7 Correct 0 ms 3988 KB Output is correct
8 Correct 0 ms 3988 KB Output is correct
9 Correct 0 ms 3988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3988 KB Output is correct
2 Correct 0 ms 3988 KB Output is correct
3 Correct 0 ms 3988 KB Output is correct
4 Correct 0 ms 3988 KB Output is correct
5 Correct 0 ms 3988 KB Output is correct
6 Correct 0 ms 3988 KB Output is correct
7 Correct 0 ms 3988 KB Output is correct
8 Correct 0 ms 3988 KB Output is correct
9 Correct 0 ms 3988 KB Output is correct
10 Correct 0 ms 3988 KB Output is correct
11 Correct 0 ms 3988 KB Output is correct
12 Correct 0 ms 3988 KB Output is correct
13 Correct 0 ms 3988 KB Output is correct
14 Correct 0 ms 3988 KB Output is correct
15 Correct 0 ms 3988 KB Output is correct
16 Correct 0 ms 3988 KB Output is correct
17 Correct 0 ms 3988 KB Output is correct
18 Correct 0 ms 3988 KB Output is correct
19 Correct 0 ms 3988 KB Output is correct
20 Correct 0 ms 3988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3988 KB Output is correct
2 Correct 0 ms 3988 KB Output is correct
3 Correct 0 ms 3988 KB Output is correct
4 Correct 0 ms 3988 KB Output is correct
5 Correct 0 ms 3988 KB Output is correct
6 Correct 0 ms 3988 KB Output is correct
7 Correct 0 ms 3988 KB Output is correct
8 Correct 0 ms 3988 KB Output is correct
9 Correct 0 ms 3988 KB Output is correct
10 Correct 0 ms 3988 KB Output is correct
11 Correct 0 ms 3988 KB Output is correct
12 Correct 0 ms 3988 KB Output is correct
13 Correct 0 ms 3988 KB Output is correct
14 Correct 0 ms 3988 KB Output is correct
15 Correct 0 ms 3988 KB Output is correct
16 Correct 0 ms 3988 KB Output is correct
17 Correct 0 ms 3988 KB Output is correct
18 Correct 0 ms 3988 KB Output is correct
19 Correct 0 ms 3988 KB Output is correct
20 Correct 0 ms 3988 KB Output is correct
21 Correct 0 ms 3988 KB Output is correct
22 Correct 0 ms 3988 KB Output is correct
23 Correct 0 ms 3988 KB Output is correct
24 Correct 3 ms 3988 KB Output is correct
25 Correct 3 ms 3988 KB Output is correct
26 Correct 3 ms 3988 KB Output is correct
27 Correct 0 ms 3988 KB Output is correct
28 Correct 0 ms 3988 KB Output is correct
29 Correct 0 ms 3988 KB Output is correct
30 Correct 0 ms 3988 KB Output is correct
31 Correct 6 ms 3988 KB Output is correct
32 Correct 3 ms 3988 KB Output is correct
33 Correct 0 ms 3988 KB Output is correct
34 Correct 0 ms 3988 KB Output is correct
35 Correct 0 ms 3988 KB Output is correct
36 Correct 3 ms 3988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3988 KB Output is correct
2 Correct 0 ms 3988 KB Output is correct
3 Correct 0 ms 3988 KB Output is correct
4 Correct 0 ms 3988 KB Output is correct
5 Correct 0 ms 3988 KB Output is correct
6 Correct 0 ms 3988 KB Output is correct
7 Correct 0 ms 3988 KB Output is correct
8 Correct 0 ms 3988 KB Output is correct
9 Correct 0 ms 3988 KB Output is correct
10 Correct 0 ms 3988 KB Output is correct
11 Correct 0 ms 3988 KB Output is correct
12 Correct 0 ms 3988 KB Output is correct
13 Correct 0 ms 3988 KB Output is correct
14 Correct 0 ms 3988 KB Output is correct
15 Correct 0 ms 3988 KB Output is correct
16 Correct 0 ms 3988 KB Output is correct
17 Correct 0 ms 3988 KB Output is correct
18 Correct 0 ms 3988 KB Output is correct
19 Correct 0 ms 3988 KB Output is correct
20 Correct 0 ms 3988 KB Output is correct
21 Correct 0 ms 3988 KB Output is correct
22 Correct 0 ms 3988 KB Output is correct
23 Correct 0 ms 3988 KB Output is correct
24 Correct 3 ms 3988 KB Output is correct
25 Correct 3 ms 3988 KB Output is correct
26 Correct 3 ms 3988 KB Output is correct
27 Correct 0 ms 3988 KB Output is correct
28 Correct 0 ms 3988 KB Output is correct
29 Correct 0 ms 3988 KB Output is correct
30 Correct 0 ms 3988 KB Output is correct
31 Correct 6 ms 3988 KB Output is correct
32 Correct 3 ms 3988 KB Output is correct
33 Correct 0 ms 3988 KB Output is correct
34 Correct 0 ms 3988 KB Output is correct
35 Correct 0 ms 3988 KB Output is correct
36 Correct 3 ms 3988 KB Output is correct
37 Correct 26 ms 4128 KB Output is correct
38 Correct 26 ms 4128 KB Output is correct
39 Correct 13 ms 3988 KB Output is correct
40 Correct 93 ms 4128 KB Output is correct
41 Correct 13 ms 3988 KB Output is correct
42 Correct 69 ms 4128 KB Output is correct
43 Correct 63 ms 4260 KB Output is correct
44 Correct 69 ms 4260 KB Output is correct
45 Correct 73 ms 4260 KB Output is correct
46 Correct 76 ms 3988 KB Output is correct
47 Correct 93 ms 4128 KB Output is correct
48 Correct 39 ms 4260 KB Output is correct
49 Correct 26 ms 4128 KB Output is correct
50 Correct 96 ms 4128 KB Output is correct
51 Correct 0 ms 3988 KB Output is correct
52 Correct 69 ms 4260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3988 KB Output is correct
2 Correct 0 ms 3988 KB Output is correct
3 Correct 0 ms 3988 KB Output is correct
4 Correct 0 ms 3988 KB Output is correct
5 Correct 0 ms 3988 KB Output is correct
6 Correct 0 ms 3988 KB Output is correct
7 Correct 0 ms 3988 KB Output is correct
8 Correct 0 ms 3988 KB Output is correct
9 Correct 0 ms 3988 KB Output is correct
10 Correct 0 ms 3988 KB Output is correct
11 Correct 0 ms 3988 KB Output is correct
12 Correct 0 ms 3988 KB Output is correct
13 Correct 0 ms 3988 KB Output is correct
14 Correct 0 ms 3988 KB Output is correct
15 Correct 0 ms 3988 KB Output is correct
16 Correct 0 ms 3988 KB Output is correct
17 Correct 0 ms 3988 KB Output is correct
18 Correct 0 ms 3988 KB Output is correct
19 Correct 0 ms 3988 KB Output is correct
20 Correct 0 ms 3988 KB Output is correct
21 Correct 0 ms 3988 KB Output is correct
22 Correct 0 ms 3988 KB Output is correct
23 Correct 0 ms 3988 KB Output is correct
24 Correct 3 ms 3988 KB Output is correct
25 Correct 3 ms 3988 KB Output is correct
26 Correct 3 ms 3988 KB Output is correct
27 Correct 0 ms 3988 KB Output is correct
28 Correct 0 ms 3988 KB Output is correct
29 Correct 0 ms 3988 KB Output is correct
30 Correct 0 ms 3988 KB Output is correct
31 Correct 6 ms 3988 KB Output is correct
32 Correct 3 ms 3988 KB Output is correct
33 Correct 0 ms 3988 KB Output is correct
34 Correct 0 ms 3988 KB Output is correct
35 Correct 0 ms 3988 KB Output is correct
36 Correct 3 ms 3988 KB Output is correct
37 Correct 26 ms 4128 KB Output is correct
38 Correct 26 ms 4128 KB Output is correct
39 Correct 13 ms 3988 KB Output is correct
40 Correct 93 ms 4128 KB Output is correct
41 Correct 13 ms 3988 KB Output is correct
42 Correct 69 ms 4128 KB Output is correct
43 Correct 63 ms 4260 KB Output is correct
44 Correct 69 ms 4260 KB Output is correct
45 Correct 73 ms 4260 KB Output is correct
46 Correct 76 ms 3988 KB Output is correct
47 Correct 93 ms 4128 KB Output is correct
48 Correct 39 ms 4260 KB Output is correct
49 Correct 26 ms 4128 KB Output is correct
50 Correct 96 ms 4128 KB Output is correct
51 Correct 0 ms 3988 KB Output is correct
52 Correct 69 ms 4260 KB Output is correct
53 Correct 126 ms 4260 KB Output is correct
54 Correct 163 ms 4260 KB Output is correct
55 Correct 136 ms 4456 KB Output is correct
56 Correct 169 ms 4260 KB Output is correct
57 Correct 163 ms 4456 KB Output is correct
58 Correct 226 ms 4260 KB Output is correct
59 Correct 196 ms 4456 KB Output is correct
60 Correct 0 ms 3988 KB Output is correct
61 Correct 229 ms 4456 KB Output is correct
62 Correct 176 ms 4456 KB Output is correct
63 Correct 146 ms 4456 KB Output is correct
64 Correct 143 ms 4456 KB Output is correct
65 Correct 13 ms 3988 KB Output is correct
66 Correct 36 ms 4128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3988 KB Output is correct
2 Correct 0 ms 3988 KB Output is correct
3 Correct 0 ms 3988 KB Output is correct
4 Correct 0 ms 3988 KB Output is correct
5 Correct 0 ms 3988 KB Output is correct
6 Correct 0 ms 3988 KB Output is correct
7 Correct 0 ms 3988 KB Output is correct
8 Correct 0 ms 3988 KB Output is correct
9 Correct 0 ms 3988 KB Output is correct
10 Correct 0 ms 3988 KB Output is correct
11 Correct 0 ms 3988 KB Output is correct
12 Correct 0 ms 3988 KB Output is correct
13 Correct 0 ms 3988 KB Output is correct
14 Correct 0 ms 3988 KB Output is correct
15 Correct 0 ms 3988 KB Output is correct
16 Correct 0 ms 3988 KB Output is correct
17 Correct 0 ms 3988 KB Output is correct
18 Correct 0 ms 3988 KB Output is correct
19 Correct 0 ms 3988 KB Output is correct
20 Correct 0 ms 3988 KB Output is correct
21 Correct 0 ms 3988 KB Output is correct
22 Correct 0 ms 3988 KB Output is correct
23 Correct 0 ms 3988 KB Output is correct
24 Correct 3 ms 3988 KB Output is correct
25 Correct 3 ms 3988 KB Output is correct
26 Correct 3 ms 3988 KB Output is correct
27 Correct 0 ms 3988 KB Output is correct
28 Correct 0 ms 3988 KB Output is correct
29 Correct 0 ms 3988 KB Output is correct
30 Correct 0 ms 3988 KB Output is correct
31 Correct 6 ms 3988 KB Output is correct
32 Correct 3 ms 3988 KB Output is correct
33 Correct 0 ms 3988 KB Output is correct
34 Correct 0 ms 3988 KB Output is correct
35 Correct 0 ms 3988 KB Output is correct
36 Correct 3 ms 3988 KB Output is correct
37 Correct 26 ms 4128 KB Output is correct
38 Correct 26 ms 4128 KB Output is correct
39 Correct 13 ms 3988 KB Output is correct
40 Correct 93 ms 4128 KB Output is correct
41 Correct 13 ms 3988 KB Output is correct
42 Correct 69 ms 4128 KB Output is correct
43 Correct 63 ms 4260 KB Output is correct
44 Correct 69 ms 4260 KB Output is correct
45 Correct 73 ms 4260 KB Output is correct
46 Correct 76 ms 3988 KB Output is correct
47 Correct 93 ms 4128 KB Output is correct
48 Correct 39 ms 4260 KB Output is correct
49 Correct 26 ms 4128 KB Output is correct
50 Correct 96 ms 4128 KB Output is correct
51 Correct 0 ms 3988 KB Output is correct
52 Correct 69 ms 4260 KB Output is correct
53 Correct 126 ms 4260 KB Output is correct
54 Correct 163 ms 4260 KB Output is correct
55 Correct 136 ms 4456 KB Output is correct
56 Correct 169 ms 4260 KB Output is correct
57 Correct 163 ms 4456 KB Output is correct
58 Correct 226 ms 4260 KB Output is correct
59 Correct 196 ms 4456 KB Output is correct
60 Correct 0 ms 3988 KB Output is correct
61 Correct 229 ms 4456 KB Output is correct
62 Correct 176 ms 4456 KB Output is correct
63 Correct 146 ms 4456 KB Output is correct
64 Correct 143 ms 4456 KB Output is correct
65 Correct 13 ms 3988 KB Output is correct
66 Correct 36 ms 4128 KB Output is correct
67 Correct 306 ms 4456 KB Output is correct
68 Correct 129 ms 3988 KB Output is correct
69 Correct 429 ms 4840 KB Output is correct
70 Correct 693 ms 4456 KB Output is correct
71 Correct 669 ms 4456 KB Output is correct
72 Correct 0 ms 3988 KB Output is correct
73 Correct 0 ms 3988 KB Output is correct
74 Correct 526 ms 4840 KB Output is correct
75 Correct 686 ms 4840 KB Output is correct
76 Correct 403 ms 4840 KB Output is correct
77 Correct 489 ms 4840 KB Output is correct