Submission #661098

# Submission time Handle Problem Language Result Execution time Memory
661098 2022-11-24T11:47:41 Z Kaztaev_Alisher Bootfall (IZhO17_bootfall) C++17
65 / 100
197 ms 262144 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[N][M];
int a[N];
vector<int> ans;

void solve(){
	int n;
	cin >> n;
	ll sum = 0;
	for(int i = 1; i <= n ; i++) {
		cin >> a[i];
		sum += a[i];
	}
	dp[0][0] = 1;
	for(int i = 1; i <= n ; i++) {
		for(int j = sum; j >= a[i]; j--){
			dp[0][j] += dp[0][j-a[i]];
		}
	}
	if(sum % 2 == 1 || dp[0][(sum>>1)] == 0){
		cout << 0;
		return;
	}
	for(int i = 1; i <= n; i++){
		for(int j = 0; j <= sum; j++) dp[i][j] = dp[0][j];
		for(int j = a[i]; j <= sum; j++) dp[i][j] -= dp[i][j-a[i]];
	}
	for(int i = 1; i <= sum; i++){
		int cnt = 0;
		for(int j = 1; j <= n; j++){
			int ob = sum-a[j]+i;
			if(ob % 2 == 0 && dp[j][ob/2-i]) cnt++;
		}
		if(cnt==n) ans.pb(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 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 2 ms 1492 KB Output is correct
22 Correct 2 ms 1744 KB Output is correct
23 Correct 1 ms 1108 KB Output is correct
24 Correct 3 ms 2644 KB Output is correct
25 Correct 5 ms 4180 KB Output is correct
26 Correct 5 ms 4692 KB Output is correct
27 Correct 4 ms 4436 KB Output is correct
28 Correct 5 ms 4652 KB Output is correct
29 Correct 5 ms 4692 KB Output is correct
30 Correct 4 ms 2900 KB Output is correct
31 Correct 4 ms 3892 KB Output is correct
32 Correct 3 ms 2772 KB Output is correct
33 Correct 5 ms 4820 KB Output is correct
34 Correct 5 ms 4820 KB Output is correct
35 Correct 8 ms 4820 KB Output is correct
36 Correct 3 ms 2772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 2 ms 1492 KB Output is correct
22 Correct 2 ms 1744 KB Output is correct
23 Correct 1 ms 1108 KB Output is correct
24 Correct 3 ms 2644 KB Output is correct
25 Correct 5 ms 4180 KB Output is correct
26 Correct 5 ms 4692 KB Output is correct
27 Correct 4 ms 4436 KB Output is correct
28 Correct 5 ms 4652 KB Output is correct
29 Correct 5 ms 4692 KB Output is correct
30 Correct 4 ms 2900 KB Output is correct
31 Correct 4 ms 3892 KB Output is correct
32 Correct 3 ms 2772 KB Output is correct
33 Correct 5 ms 4820 KB Output is correct
34 Correct 5 ms 4820 KB Output is correct
35 Correct 8 ms 4820 KB Output is correct
36 Correct 3 ms 2772 KB Output is correct
37 Correct 20 ms 16852 KB Output is correct
38 Correct 19 ms 17204 KB Output is correct
39 Correct 63 ms 61864 KB Output is correct
40 Correct 38 ms 36352 KB Output is correct
41 Correct 82 ms 79084 KB Output is correct
42 Correct 34 ms 31440 KB Output is correct
43 Correct 65 ms 54852 KB Output is correct
44 Correct 60 ms 56664 KB Output is correct
45 Correct 61 ms 57612 KB Output is correct
46 Correct 40 ms 35292 KB Output is correct
47 Correct 37 ms 33868 KB Output is correct
48 Correct 67 ms 62124 KB Output is correct
49 Correct 63 ms 62260 KB Output is correct
50 Correct 38 ms 34064 KB Output is correct
51 Correct 4 ms 340 KB Output is correct
52 Correct 83 ms 76376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 2 ms 1492 KB Output is correct
22 Correct 2 ms 1744 KB Output is correct
23 Correct 1 ms 1108 KB Output is correct
24 Correct 3 ms 2644 KB Output is correct
25 Correct 5 ms 4180 KB Output is correct
26 Correct 5 ms 4692 KB Output is correct
27 Correct 4 ms 4436 KB Output is correct
28 Correct 5 ms 4652 KB Output is correct
29 Correct 5 ms 4692 KB Output is correct
30 Correct 4 ms 2900 KB Output is correct
31 Correct 4 ms 3892 KB Output is correct
32 Correct 3 ms 2772 KB Output is correct
33 Correct 5 ms 4820 KB Output is correct
34 Correct 5 ms 4820 KB Output is correct
35 Correct 8 ms 4820 KB Output is correct
36 Correct 3 ms 2772 KB Output is correct
37 Correct 20 ms 16852 KB Output is correct
38 Correct 19 ms 17204 KB Output is correct
39 Correct 63 ms 61864 KB Output is correct
40 Correct 38 ms 36352 KB Output is correct
41 Correct 82 ms 79084 KB Output is correct
42 Correct 34 ms 31440 KB Output is correct
43 Correct 65 ms 54852 KB Output is correct
44 Correct 60 ms 56664 KB Output is correct
45 Correct 61 ms 57612 KB Output is correct
46 Correct 40 ms 35292 KB Output is correct
47 Correct 37 ms 33868 KB Output is correct
48 Correct 67 ms 62124 KB Output is correct
49 Correct 63 ms 62260 KB Output is correct
50 Correct 38 ms 34064 KB Output is correct
51 Correct 4 ms 340 KB Output is correct
52 Correct 83 ms 76376 KB Output is correct
53 Correct 60 ms 55988 KB Output is correct
54 Correct 90 ms 78832 KB Output is correct
55 Correct 168 ms 155316 KB Output is correct
56 Correct 72 ms 69232 KB Output is correct
57 Correct 163 ms 163408 KB Output is correct
58 Correct 89 ms 86580 KB Output is correct
59 Correct 110 ms 107720 KB Output is correct
60 Correct 11 ms 468 KB Output is correct
61 Correct 141 ms 120376 KB Output is correct
62 Correct 124 ms 122684 KB Output is correct
63 Correct 140 ms 132832 KB Output is correct
64 Correct 130 ms 128624 KB Output is correct
65 Correct 62 ms 61692 KB Output is correct
66 Correct 68 ms 66692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 2 ms 1492 KB Output is correct
22 Correct 2 ms 1744 KB Output is correct
23 Correct 1 ms 1108 KB Output is correct
24 Correct 3 ms 2644 KB Output is correct
25 Correct 5 ms 4180 KB Output is correct
26 Correct 5 ms 4692 KB Output is correct
27 Correct 4 ms 4436 KB Output is correct
28 Correct 5 ms 4652 KB Output is correct
29 Correct 5 ms 4692 KB Output is correct
30 Correct 4 ms 2900 KB Output is correct
31 Correct 4 ms 3892 KB Output is correct
32 Correct 3 ms 2772 KB Output is correct
33 Correct 5 ms 4820 KB Output is correct
34 Correct 5 ms 4820 KB Output is correct
35 Correct 8 ms 4820 KB Output is correct
36 Correct 3 ms 2772 KB Output is correct
37 Correct 20 ms 16852 KB Output is correct
38 Correct 19 ms 17204 KB Output is correct
39 Correct 63 ms 61864 KB Output is correct
40 Correct 38 ms 36352 KB Output is correct
41 Correct 82 ms 79084 KB Output is correct
42 Correct 34 ms 31440 KB Output is correct
43 Correct 65 ms 54852 KB Output is correct
44 Correct 60 ms 56664 KB Output is correct
45 Correct 61 ms 57612 KB Output is correct
46 Correct 40 ms 35292 KB Output is correct
47 Correct 37 ms 33868 KB Output is correct
48 Correct 67 ms 62124 KB Output is correct
49 Correct 63 ms 62260 KB Output is correct
50 Correct 38 ms 34064 KB Output is correct
51 Correct 4 ms 340 KB Output is correct
52 Correct 83 ms 76376 KB Output is correct
53 Correct 60 ms 55988 KB Output is correct
54 Correct 90 ms 78832 KB Output is correct
55 Correct 168 ms 155316 KB Output is correct
56 Correct 72 ms 69232 KB Output is correct
57 Correct 163 ms 163408 KB Output is correct
58 Correct 89 ms 86580 KB Output is correct
59 Correct 110 ms 107720 KB Output is correct
60 Correct 11 ms 468 KB Output is correct
61 Correct 141 ms 120376 KB Output is correct
62 Correct 124 ms 122684 KB Output is correct
63 Correct 140 ms 132832 KB Output is correct
64 Correct 130 ms 128624 KB Output is correct
65 Correct 62 ms 61692 KB Output is correct
66 Correct 68 ms 66692 KB Output is correct
67 Correct 130 ms 128460 KB Output is correct
68 Correct 29 ms 724 KB Output is correct
69 Runtime error 197 ms 262144 KB Execution killed with signal 9
70 Halted 0 ms 0 KB -