#include <bits/stdc++.h>
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
#define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
#define per(i,r,l) for(int i = (r); i >= (l); i--)
#define rep(i,l,r) for(int i = (l); i < (r); i++)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ss second
#define ff first
void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 5e2+5, lg = 20, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}
int dp[maxn][maxn*maxn];
int main(){
cin.tie(0) -> sync_with_stdio(0);
int n; cin >> n;
vector<int> a(n);
int sum = 0;
rep(i,0,n) cin >> a[i], sum += a[i];
dp[n][0] = 1;
rep(i,0,n) per(j,sum,a[i]) dp[n][j] += dp[n][j-a[i]], dp[n][j] -= dp[n][j]<mod?0:mod;
rep(k,0,n){
rep(i,0,sum+1) dp[k][i] = dp[n][i];
rep(j,a[k],sum+1) dp[k][j] -= dp[k][j-a[k]], dp[k][j] += dp[k][j]<0?mod:0;
}
// rep(k,0,n+1) rep(i,0,sum) er(k, i, dp[k][i]);
if((sum&1) || !dp[n][sum>>1]) return cout << "0\n", 0;
rep(i,0,n) if(a[i]%2 != a[0]%2) return cout << "0\n", 0;
vector<int> ans;
rep(i,1,sum+1) if(i%2 == a[0]%2){
bool ok = true;
rep(j,0,n){
int t = (sum - a[j] + i)>>1;
if(t > sum || !dp[j][t]) {
ok = false;
break;
}
}
if(ok) ans.pb(i);
}
cout << sz(ans) << '\n';
for(int c: ans) cout << c << ' ';
if(sz(ans)) cout << '\n';
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 |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 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 |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
468 KB |
Output is correct |
11 |
Correct |
0 ms |
468 KB |
Output is correct |
12 |
Correct |
1 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 |
0 ms |
468 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 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 |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
468 KB |
Output is correct |
11 |
Correct |
0 ms |
468 KB |
Output is correct |
12 |
Correct |
1 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 |
0 ms |
468 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 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 |
1748 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 |
6 ms |
4660 KB |
Output is correct |
27 |
Correct |
5 ms |
4436 KB |
Output is correct |
28 |
Correct |
5 ms |
4564 KB |
Output is correct |
29 |
Correct |
6 ms |
4692 KB |
Output is correct |
30 |
Correct |
3 ms |
2900 KB |
Output is correct |
31 |
Correct |
5 ms |
3924 KB |
Output is correct |
32 |
Correct |
4 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 |
5 ms |
4692 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 |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
468 KB |
Output is correct |
11 |
Correct |
0 ms |
468 KB |
Output is correct |
12 |
Correct |
1 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 |
0 ms |
468 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 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 |
1748 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 |
6 ms |
4660 KB |
Output is correct |
27 |
Correct |
5 ms |
4436 KB |
Output is correct |
28 |
Correct |
5 ms |
4564 KB |
Output is correct |
29 |
Correct |
6 ms |
4692 KB |
Output is correct |
30 |
Correct |
3 ms |
2900 KB |
Output is correct |
31 |
Correct |
5 ms |
3924 KB |
Output is correct |
32 |
Correct |
4 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 |
5 ms |
4692 KB |
Output is correct |
36 |
Correct |
3 ms |
2772 KB |
Output is correct |
37 |
Correct |
23 ms |
16796 KB |
Output is correct |
38 |
Correct |
24 ms |
17256 KB |
Output is correct |
39 |
Correct |
74 ms |
61772 KB |
Output is correct |
40 |
Correct |
50 ms |
36428 KB |
Output is correct |
41 |
Correct |
93 ms |
79068 KB |
Output is correct |
42 |
Correct |
44 ms |
31448 KB |
Output is correct |
43 |
Correct |
84 ms |
54804 KB |
Output is correct |
44 |
Correct |
79 ms |
56628 KB |
Output is correct |
45 |
Correct |
82 ms |
57672 KB |
Output is correct |
46 |
Correct |
41 ms |
35328 KB |
Output is correct |
47 |
Correct |
47 ms |
33916 KB |
Output is correct |
48 |
Correct |
83 ms |
62196 KB |
Output is correct |
49 |
Correct |
76 ms |
62256 KB |
Output is correct |
50 |
Correct |
50 ms |
34144 KB |
Output is correct |
51 |
Correct |
38 ms |
32480 KB |
Output is correct |
52 |
Correct |
109 ms |
76492 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 |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
468 KB |
Output is correct |
11 |
Correct |
0 ms |
468 KB |
Output is correct |
12 |
Correct |
1 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 |
0 ms |
468 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 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 |
1748 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 |
6 ms |
4660 KB |
Output is correct |
27 |
Correct |
5 ms |
4436 KB |
Output is correct |
28 |
Correct |
5 ms |
4564 KB |
Output is correct |
29 |
Correct |
6 ms |
4692 KB |
Output is correct |
30 |
Correct |
3 ms |
2900 KB |
Output is correct |
31 |
Correct |
5 ms |
3924 KB |
Output is correct |
32 |
Correct |
4 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 |
5 ms |
4692 KB |
Output is correct |
36 |
Correct |
3 ms |
2772 KB |
Output is correct |
37 |
Correct |
23 ms |
16796 KB |
Output is correct |
38 |
Correct |
24 ms |
17256 KB |
Output is correct |
39 |
Correct |
74 ms |
61772 KB |
Output is correct |
40 |
Correct |
50 ms |
36428 KB |
Output is correct |
41 |
Correct |
93 ms |
79068 KB |
Output is correct |
42 |
Correct |
44 ms |
31448 KB |
Output is correct |
43 |
Correct |
84 ms |
54804 KB |
Output is correct |
44 |
Correct |
79 ms |
56628 KB |
Output is correct |
45 |
Correct |
82 ms |
57672 KB |
Output is correct |
46 |
Correct |
41 ms |
35328 KB |
Output is correct |
47 |
Correct |
47 ms |
33916 KB |
Output is correct |
48 |
Correct |
83 ms |
62196 KB |
Output is correct |
49 |
Correct |
76 ms |
62256 KB |
Output is correct |
50 |
Correct |
50 ms |
34144 KB |
Output is correct |
51 |
Correct |
38 ms |
32480 KB |
Output is correct |
52 |
Correct |
109 ms |
76492 KB |
Output is correct |
53 |
Correct |
77 ms |
55884 KB |
Output is correct |
54 |
Correct |
111 ms |
78900 KB |
Output is correct |
55 |
Correct |
218 ms |
155124 KB |
Output is correct |
56 |
Correct |
97 ms |
69492 KB |
Output is correct |
57 |
Correct |
222 ms |
163340 KB |
Output is correct |
58 |
Correct |
123 ms |
86604 KB |
Output is correct |
59 |
Correct |
152 ms |
107628 KB |
Output is correct |
60 |
Correct |
101 ms |
86548 KB |
Output is correct |
61 |
Correct |
177 ms |
120344 KB |
Output is correct |
62 |
Correct |
187 ms |
122716 KB |
Output is correct |
63 |
Correct |
208 ms |
132752 KB |
Output is correct |
64 |
Correct |
195 ms |
128596 KB |
Output is correct |
65 |
Correct |
86 ms |
61584 KB |
Output is correct |
66 |
Correct |
88 ms |
66708 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 |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
468 KB |
Output is correct |
11 |
Correct |
0 ms |
468 KB |
Output is correct |
12 |
Correct |
1 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 |
0 ms |
468 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 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 |
1748 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 |
6 ms |
4660 KB |
Output is correct |
27 |
Correct |
5 ms |
4436 KB |
Output is correct |
28 |
Correct |
5 ms |
4564 KB |
Output is correct |
29 |
Correct |
6 ms |
4692 KB |
Output is correct |
30 |
Correct |
3 ms |
2900 KB |
Output is correct |
31 |
Correct |
5 ms |
3924 KB |
Output is correct |
32 |
Correct |
4 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 |
5 ms |
4692 KB |
Output is correct |
36 |
Correct |
3 ms |
2772 KB |
Output is correct |
37 |
Correct |
23 ms |
16796 KB |
Output is correct |
38 |
Correct |
24 ms |
17256 KB |
Output is correct |
39 |
Correct |
74 ms |
61772 KB |
Output is correct |
40 |
Correct |
50 ms |
36428 KB |
Output is correct |
41 |
Correct |
93 ms |
79068 KB |
Output is correct |
42 |
Correct |
44 ms |
31448 KB |
Output is correct |
43 |
Correct |
84 ms |
54804 KB |
Output is correct |
44 |
Correct |
79 ms |
56628 KB |
Output is correct |
45 |
Correct |
82 ms |
57672 KB |
Output is correct |
46 |
Correct |
41 ms |
35328 KB |
Output is correct |
47 |
Correct |
47 ms |
33916 KB |
Output is correct |
48 |
Correct |
83 ms |
62196 KB |
Output is correct |
49 |
Correct |
76 ms |
62256 KB |
Output is correct |
50 |
Correct |
50 ms |
34144 KB |
Output is correct |
51 |
Correct |
38 ms |
32480 KB |
Output is correct |
52 |
Correct |
109 ms |
76492 KB |
Output is correct |
53 |
Correct |
77 ms |
55884 KB |
Output is correct |
54 |
Correct |
111 ms |
78900 KB |
Output is correct |
55 |
Correct |
218 ms |
155124 KB |
Output is correct |
56 |
Correct |
97 ms |
69492 KB |
Output is correct |
57 |
Correct |
222 ms |
163340 KB |
Output is correct |
58 |
Correct |
123 ms |
86604 KB |
Output is correct |
59 |
Correct |
152 ms |
107628 KB |
Output is correct |
60 |
Correct |
101 ms |
86548 KB |
Output is correct |
61 |
Correct |
177 ms |
120344 KB |
Output is correct |
62 |
Correct |
187 ms |
122716 KB |
Output is correct |
63 |
Correct |
208 ms |
132752 KB |
Output is correct |
64 |
Correct |
195 ms |
128596 KB |
Output is correct |
65 |
Correct |
86 ms |
61584 KB |
Output is correct |
66 |
Correct |
88 ms |
66708 KB |
Output is correct |
67 |
Correct |
196 ms |
128428 KB |
Output is correct |
68 |
Correct |
334 ms |
244764 KB |
Output is correct |
69 |
Runtime error |
431 ms |
262144 KB |
Execution killed with signal 9 |
70 |
Halted |
0 ms |
0 KB |
- |