Submission #661099

# Submission time Handle Problem Language Result Execution time Memory
661099 2022-11-24T11:49:37 Z Kaztaev_Alisher Bootfall (IZhO17_bootfall) C++17
100 / 100
568 ms 3448 KB
//#pragma GCC optomize ("Ofast")
//#pragma GCC optomize ("unroll-loops")
//#pragma GCC target ("avx,avx2,fma")

#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define sz size
#define cl clear
#define ins insert
#define ers erase
#define pii pair < int , int >
#define pll pair< long long  , long long >
#define all(x) x.begin() , x.end()
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define tostr(x) to_string(x)
#define tonum(s) atoi(s.c_str())
#define seon(x) setprecision(x)
#define bpop(x) __builtin_popcount(x)
#define deb(x) cerr << #x  << " = " << x << endl;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
const double PI = 3.14159265;

const ll N = 500+9 , M = 258000;
const ll mod = 1e9+7;
const ll inf = 1e9;
const ll INF = 1e18;

using namespace std;

int dp[M];
int a[N];
vector<int> ans;
int cnt[M];

void solve(){
	int n;
	cin >> n;
	ll sum = 0;
	for(int i = 1; i <= n ; i++) {
		cin >> a[i];
		sum += a[i];
	}
	dp[0] = 1;
	for(int i = 1; i <= n ; i++) {
		for(int j = sum; j >= a[i]; j--) dp[j] += dp[j-a[i]];
	}
	if(sum % 2 == 1 || dp[(sum>>1)] == 0){
		cout << 0;
		return;
	}
	for(int i = 1; i <= n; i++){
		for(int j = a[i]; j <= sum; j++) dp[j] -= dp[j-a[i]];
		for(int x = 1; x <= sum-a[i]; x++){
			int ob = sum-a[i]+x;
			if(ob % 2 == 0 && dp[ob/2-x]){
				cnt[x]++;
				if(cnt[x] == n) ans.pb(x);
			}
		}
		for(int j = sum; j >= a[i]; j--) dp[j] += dp[j-a[i]];
	}
	cout << ans.sz() <<"\n";
	for(int x : ans) cout << x <<" ";
}
signed main(){
	ios;
	solve();
	return 0;
}
/*
*/
 
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 4 ms 340 KB Output is correct
26 Correct 6 ms 340 KB Output is correct
27 Correct 5 ms 340 KB Output is correct
28 Correct 7 ms 340 KB Output is correct
29 Correct 6 ms 372 KB Output is correct
30 Correct 3 ms 340 KB Output is correct
31 Correct 4 ms 340 KB Output is correct
32 Correct 3 ms 368 KB Output is correct
33 Correct 5 ms 340 KB Output is correct
34 Correct 5 ms 340 KB Output is correct
35 Correct 5 ms 340 KB Output is correct
36 Correct 3 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 4 ms 340 KB Output is correct
26 Correct 6 ms 340 KB Output is correct
27 Correct 5 ms 340 KB Output is correct
28 Correct 7 ms 340 KB Output is correct
29 Correct 6 ms 372 KB Output is correct
30 Correct 3 ms 340 KB Output is correct
31 Correct 4 ms 340 KB Output is correct
32 Correct 3 ms 368 KB Output is correct
33 Correct 5 ms 340 KB Output is correct
34 Correct 5 ms 340 KB Output is correct
35 Correct 5 ms 340 KB Output is correct
36 Correct 3 ms 340 KB Output is correct
37 Correct 19 ms 612 KB Output is correct
38 Correct 19 ms 616 KB Output is correct
39 Correct 69 ms 792 KB Output is correct
40 Correct 48 ms 688 KB Output is correct
41 Correct 92 ms 884 KB Output is correct
42 Correct 34 ms 688 KB Output is correct
43 Correct 63 ms 1100 KB Output is correct
44 Correct 67 ms 1132 KB Output is correct
45 Correct 67 ms 1028 KB Output is correct
46 Correct 38 ms 468 KB Output is correct
47 Correct 43 ms 708 KB Output is correct
48 Correct 73 ms 1060 KB Output is correct
49 Correct 71 ms 808 KB Output is correct
50 Correct 38 ms 716 KB Output is correct
51 Correct 6 ms 340 KB Output is correct
52 Correct 92 ms 1240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 4 ms 340 KB Output is correct
26 Correct 6 ms 340 KB Output is correct
27 Correct 5 ms 340 KB Output is correct
28 Correct 7 ms 340 KB Output is correct
29 Correct 6 ms 372 KB Output is correct
30 Correct 3 ms 340 KB Output is correct
31 Correct 4 ms 340 KB Output is correct
32 Correct 3 ms 368 KB Output is correct
33 Correct 5 ms 340 KB Output is correct
34 Correct 5 ms 340 KB Output is correct
35 Correct 5 ms 340 KB Output is correct
36 Correct 3 ms 340 KB Output is correct
37 Correct 19 ms 612 KB Output is correct
38 Correct 19 ms 616 KB Output is correct
39 Correct 69 ms 792 KB Output is correct
40 Correct 48 ms 688 KB Output is correct
41 Correct 92 ms 884 KB Output is correct
42 Correct 34 ms 688 KB Output is correct
43 Correct 63 ms 1100 KB Output is correct
44 Correct 67 ms 1132 KB Output is correct
45 Correct 67 ms 1028 KB Output is correct
46 Correct 38 ms 468 KB Output is correct
47 Correct 43 ms 708 KB Output is correct
48 Correct 73 ms 1060 KB Output is correct
49 Correct 71 ms 808 KB Output is correct
50 Correct 38 ms 716 KB Output is correct
51 Correct 6 ms 340 KB Output is correct
52 Correct 92 ms 1240 KB Output is correct
53 Correct 65 ms 1012 KB Output is correct
54 Correct 92 ms 1072 KB Output is correct
55 Correct 203 ms 1788 KB Output is correct
56 Correct 84 ms 1060 KB Output is correct
57 Correct 186 ms 1868 KB Output is correct
58 Correct 103 ms 1176 KB Output is correct
59 Correct 131 ms 1296 KB Output is correct
60 Correct 21 ms 572 KB Output is correct
61 Correct 136 ms 1496 KB Output is correct
62 Correct 142 ms 1580 KB Output is correct
63 Correct 155 ms 1644 KB Output is correct
64 Correct 149 ms 1624 KB Output is correct
65 Correct 70 ms 688 KB Output is correct
66 Correct 71 ms 732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 4 ms 340 KB Output is correct
26 Correct 6 ms 340 KB Output is correct
27 Correct 5 ms 340 KB Output is correct
28 Correct 7 ms 340 KB Output is correct
29 Correct 6 ms 372 KB Output is correct
30 Correct 3 ms 340 KB Output is correct
31 Correct 4 ms 340 KB Output is correct
32 Correct 3 ms 368 KB Output is correct
33 Correct 5 ms 340 KB Output is correct
34 Correct 5 ms 340 KB Output is correct
35 Correct 5 ms 340 KB Output is correct
36 Correct 3 ms 340 KB Output is correct
37 Correct 19 ms 612 KB Output is correct
38 Correct 19 ms 616 KB Output is correct
39 Correct 69 ms 792 KB Output is correct
40 Correct 48 ms 688 KB Output is correct
41 Correct 92 ms 884 KB Output is correct
42 Correct 34 ms 688 KB Output is correct
43 Correct 63 ms 1100 KB Output is correct
44 Correct 67 ms 1132 KB Output is correct
45 Correct 67 ms 1028 KB Output is correct
46 Correct 38 ms 468 KB Output is correct
47 Correct 43 ms 708 KB Output is correct
48 Correct 73 ms 1060 KB Output is correct
49 Correct 71 ms 808 KB Output is correct
50 Correct 38 ms 716 KB Output is correct
51 Correct 6 ms 340 KB Output is correct
52 Correct 92 ms 1240 KB Output is correct
53 Correct 65 ms 1012 KB Output is correct
54 Correct 92 ms 1072 KB Output is correct
55 Correct 203 ms 1788 KB Output is correct
56 Correct 84 ms 1060 KB Output is correct
57 Correct 186 ms 1868 KB Output is correct
58 Correct 103 ms 1176 KB Output is correct
59 Correct 131 ms 1296 KB Output is correct
60 Correct 21 ms 572 KB Output is correct
61 Correct 136 ms 1496 KB Output is correct
62 Correct 142 ms 1580 KB Output is correct
63 Correct 155 ms 1644 KB Output is correct
64 Correct 149 ms 1624 KB Output is correct
65 Correct 70 ms 688 KB Output is correct
66 Correct 71 ms 732 KB Output is correct
67 Correct 157 ms 1460 KB Output is correct
68 Correct 42 ms 724 KB Output is correct
69 Correct 474 ms 3116 KB Output is correct
70 Correct 297 ms 2100 KB Output is correct
71 Correct 282 ms 2060 KB Output is correct
72 Correct 293 ms 1292 KB Output is correct
73 Correct 291 ms 1312 KB Output is correct
74 Correct 516 ms 3212 KB Output is correct
75 Correct 399 ms 2696 KB Output is correct
76 Correct 568 ms 3376 KB Output is correct
77 Correct 559 ms 3448 KB Output is correct