#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define endl '\n'
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
const int mod = 1e9 + 7;
const int N = 502 * 502;
const ll inf = 1e18;
int dp[N];
int ok[N];
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (int i=0;i<n;i++){
cin >> a[i];
}
sort(all(a));// useless :D
dp[0]=1;
for (int i=0;i<n;i++)
for (int j=N-1;j>=a[i];j--)
dp[j] += dp[j-a[i]];
int sum=0;
for_each(all(a),[&](int x){ sum+=x;});
bool flag = (sum%2==0 && dp[sum/2]);
if(!flag) return cout << 0, 0;
for (int i=0;i<n;i++){
// I will remove a[i]
sum -= a[i];
for (int j=a[i];j<N;j++)
dp[j] -= dp[j-a[i]];
for (int j=0;j<N;j++)
if (dp[j]&&2*j-sum >= 0) ok[2*j-sum]++;
for (int j=N-1;j>=a[i];j--)
dp[j] += dp[j-a[i]];
sum += a[i];
}
vector<int> ans;
for (int i=0;i<N;i++) if (ok[i]==n) ans.pb(i);
cout << sz(ans) << endl;
for (auto it : ans){
cout << it << ' ';
}
cout << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2260 KB |
Output is correct |
2 |
Correct |
6 ms |
2260 KB |
Output is correct |
3 |
Correct |
2 ms |
2256 KB |
Output is correct |
4 |
Correct |
4 ms |
2260 KB |
Output is correct |
5 |
Correct |
10 ms |
2260 KB |
Output is correct |
6 |
Correct |
7 ms |
2260 KB |
Output is correct |
7 |
Correct |
6 ms |
2260 KB |
Output is correct |
8 |
Correct |
9 ms |
2260 KB |
Output is correct |
9 |
Correct |
8 ms |
2248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2260 KB |
Output is correct |
2 |
Correct |
6 ms |
2260 KB |
Output is correct |
3 |
Correct |
2 ms |
2256 KB |
Output is correct |
4 |
Correct |
4 ms |
2260 KB |
Output is correct |
5 |
Correct |
10 ms |
2260 KB |
Output is correct |
6 |
Correct |
7 ms |
2260 KB |
Output is correct |
7 |
Correct |
6 ms |
2260 KB |
Output is correct |
8 |
Correct |
9 ms |
2260 KB |
Output is correct |
9 |
Correct |
8 ms |
2248 KB |
Output is correct |
10 |
Correct |
21 ms |
2308 KB |
Output is correct |
11 |
Correct |
23 ms |
2260 KB |
Output is correct |
12 |
Correct |
21 ms |
2284 KB |
Output is correct |
13 |
Correct |
20 ms |
2260 KB |
Output is correct |
14 |
Correct |
20 ms |
2300 KB |
Output is correct |
15 |
Correct |
30 ms |
2260 KB |
Output is correct |
16 |
Correct |
23 ms |
2300 KB |
Output is correct |
17 |
Correct |
19 ms |
2252 KB |
Output is correct |
18 |
Correct |
19 ms |
2304 KB |
Output is correct |
19 |
Correct |
22 ms |
2260 KB |
Output is correct |
20 |
Correct |
21 ms |
2260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2260 KB |
Output is correct |
2 |
Correct |
6 ms |
2260 KB |
Output is correct |
3 |
Correct |
2 ms |
2256 KB |
Output is correct |
4 |
Correct |
4 ms |
2260 KB |
Output is correct |
5 |
Correct |
10 ms |
2260 KB |
Output is correct |
6 |
Correct |
7 ms |
2260 KB |
Output is correct |
7 |
Correct |
6 ms |
2260 KB |
Output is correct |
8 |
Correct |
9 ms |
2260 KB |
Output is correct |
9 |
Correct |
8 ms |
2248 KB |
Output is correct |
10 |
Correct |
21 ms |
2308 KB |
Output is correct |
11 |
Correct |
23 ms |
2260 KB |
Output is correct |
12 |
Correct |
21 ms |
2284 KB |
Output is correct |
13 |
Correct |
20 ms |
2260 KB |
Output is correct |
14 |
Correct |
20 ms |
2300 KB |
Output is correct |
15 |
Correct |
30 ms |
2260 KB |
Output is correct |
16 |
Correct |
23 ms |
2300 KB |
Output is correct |
17 |
Correct |
19 ms |
2252 KB |
Output is correct |
18 |
Correct |
19 ms |
2304 KB |
Output is correct |
19 |
Correct |
22 ms |
2260 KB |
Output is correct |
20 |
Correct |
21 ms |
2260 KB |
Output is correct |
21 |
Correct |
43 ms |
2304 KB |
Output is correct |
22 |
Correct |
72 ms |
2304 KB |
Output is correct |
23 |
Correct |
44 ms |
2312 KB |
Output is correct |
24 |
Correct |
63 ms |
2320 KB |
Output is correct |
25 |
Correct |
65 ms |
2352 KB |
Output is correct |
26 |
Correct |
65 ms |
2352 KB |
Output is correct |
27 |
Correct |
65 ms |
2360 KB |
Output is correct |
28 |
Correct |
65 ms |
2356 KB |
Output is correct |
29 |
Correct |
73 ms |
2356 KB |
Output is correct |
30 |
Correct |
67 ms |
2304 KB |
Output is correct |
31 |
Correct |
66 ms |
2352 KB |
Output is correct |
32 |
Correct |
78 ms |
2368 KB |
Output is correct |
33 |
Correct |
66 ms |
2360 KB |
Output is correct |
34 |
Correct |
65 ms |
2308 KB |
Output is correct |
35 |
Correct |
71 ms |
2356 KB |
Output is correct |
36 |
Correct |
68 ms |
2320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2260 KB |
Output is correct |
2 |
Correct |
6 ms |
2260 KB |
Output is correct |
3 |
Correct |
2 ms |
2256 KB |
Output is correct |
4 |
Correct |
4 ms |
2260 KB |
Output is correct |
5 |
Correct |
10 ms |
2260 KB |
Output is correct |
6 |
Correct |
7 ms |
2260 KB |
Output is correct |
7 |
Correct |
6 ms |
2260 KB |
Output is correct |
8 |
Correct |
9 ms |
2260 KB |
Output is correct |
9 |
Correct |
8 ms |
2248 KB |
Output is correct |
10 |
Correct |
21 ms |
2308 KB |
Output is correct |
11 |
Correct |
23 ms |
2260 KB |
Output is correct |
12 |
Correct |
21 ms |
2284 KB |
Output is correct |
13 |
Correct |
20 ms |
2260 KB |
Output is correct |
14 |
Correct |
20 ms |
2300 KB |
Output is correct |
15 |
Correct |
30 ms |
2260 KB |
Output is correct |
16 |
Correct |
23 ms |
2300 KB |
Output is correct |
17 |
Correct |
19 ms |
2252 KB |
Output is correct |
18 |
Correct |
19 ms |
2304 KB |
Output is correct |
19 |
Correct |
22 ms |
2260 KB |
Output is correct |
20 |
Correct |
21 ms |
2260 KB |
Output is correct |
21 |
Correct |
43 ms |
2304 KB |
Output is correct |
22 |
Correct |
72 ms |
2304 KB |
Output is correct |
23 |
Correct |
44 ms |
2312 KB |
Output is correct |
24 |
Correct |
63 ms |
2320 KB |
Output is correct |
25 |
Correct |
65 ms |
2352 KB |
Output is correct |
26 |
Correct |
65 ms |
2352 KB |
Output is correct |
27 |
Correct |
65 ms |
2360 KB |
Output is correct |
28 |
Correct |
65 ms |
2356 KB |
Output is correct |
29 |
Correct |
73 ms |
2356 KB |
Output is correct |
30 |
Correct |
67 ms |
2304 KB |
Output is correct |
31 |
Correct |
66 ms |
2352 KB |
Output is correct |
32 |
Correct |
78 ms |
2368 KB |
Output is correct |
33 |
Correct |
66 ms |
2360 KB |
Output is correct |
34 |
Correct |
65 ms |
2308 KB |
Output is correct |
35 |
Correct |
71 ms |
2356 KB |
Output is correct |
36 |
Correct |
68 ms |
2320 KB |
Output is correct |
37 |
Correct |
158 ms |
2692 KB |
Output is correct |
38 |
Correct |
130 ms |
2664 KB |
Output is correct |
39 |
Correct |
160 ms |
2672 KB |
Output is correct |
40 |
Correct |
186 ms |
2796 KB |
Output is correct |
41 |
Correct |
188 ms |
2824 KB |
Output is correct |
42 |
Correct |
196 ms |
2772 KB |
Output is correct |
43 |
Correct |
160 ms |
3092 KB |
Output is correct |
44 |
Correct |
169 ms |
3104 KB |
Output is correct |
45 |
Correct |
163 ms |
3148 KB |
Output is correct |
46 |
Correct |
172 ms |
2416 KB |
Output is correct |
47 |
Correct |
169 ms |
2788 KB |
Output is correct |
48 |
Correct |
170 ms |
3052 KB |
Output is correct |
49 |
Correct |
163 ms |
2888 KB |
Output is correct |
50 |
Correct |
207 ms |
2796 KB |
Output is correct |
51 |
Correct |
40 ms |
2260 KB |
Output is correct |
52 |
Correct |
190 ms |
3348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2260 KB |
Output is correct |
2 |
Correct |
6 ms |
2260 KB |
Output is correct |
3 |
Correct |
2 ms |
2256 KB |
Output is correct |
4 |
Correct |
4 ms |
2260 KB |
Output is correct |
5 |
Correct |
10 ms |
2260 KB |
Output is correct |
6 |
Correct |
7 ms |
2260 KB |
Output is correct |
7 |
Correct |
6 ms |
2260 KB |
Output is correct |
8 |
Correct |
9 ms |
2260 KB |
Output is correct |
9 |
Correct |
8 ms |
2248 KB |
Output is correct |
10 |
Correct |
21 ms |
2308 KB |
Output is correct |
11 |
Correct |
23 ms |
2260 KB |
Output is correct |
12 |
Correct |
21 ms |
2284 KB |
Output is correct |
13 |
Correct |
20 ms |
2260 KB |
Output is correct |
14 |
Correct |
20 ms |
2300 KB |
Output is correct |
15 |
Correct |
30 ms |
2260 KB |
Output is correct |
16 |
Correct |
23 ms |
2300 KB |
Output is correct |
17 |
Correct |
19 ms |
2252 KB |
Output is correct |
18 |
Correct |
19 ms |
2304 KB |
Output is correct |
19 |
Correct |
22 ms |
2260 KB |
Output is correct |
20 |
Correct |
21 ms |
2260 KB |
Output is correct |
21 |
Correct |
43 ms |
2304 KB |
Output is correct |
22 |
Correct |
72 ms |
2304 KB |
Output is correct |
23 |
Correct |
44 ms |
2312 KB |
Output is correct |
24 |
Correct |
63 ms |
2320 KB |
Output is correct |
25 |
Correct |
65 ms |
2352 KB |
Output is correct |
26 |
Correct |
65 ms |
2352 KB |
Output is correct |
27 |
Correct |
65 ms |
2360 KB |
Output is correct |
28 |
Correct |
65 ms |
2356 KB |
Output is correct |
29 |
Correct |
73 ms |
2356 KB |
Output is correct |
30 |
Correct |
67 ms |
2304 KB |
Output is correct |
31 |
Correct |
66 ms |
2352 KB |
Output is correct |
32 |
Correct |
78 ms |
2368 KB |
Output is correct |
33 |
Correct |
66 ms |
2360 KB |
Output is correct |
34 |
Correct |
65 ms |
2308 KB |
Output is correct |
35 |
Correct |
71 ms |
2356 KB |
Output is correct |
36 |
Correct |
68 ms |
2320 KB |
Output is correct |
37 |
Correct |
158 ms |
2692 KB |
Output is correct |
38 |
Correct |
130 ms |
2664 KB |
Output is correct |
39 |
Correct |
160 ms |
2672 KB |
Output is correct |
40 |
Correct |
186 ms |
2796 KB |
Output is correct |
41 |
Correct |
188 ms |
2824 KB |
Output is correct |
42 |
Correct |
196 ms |
2772 KB |
Output is correct |
43 |
Correct |
160 ms |
3092 KB |
Output is correct |
44 |
Correct |
169 ms |
3104 KB |
Output is correct |
45 |
Correct |
163 ms |
3148 KB |
Output is correct |
46 |
Correct |
172 ms |
2416 KB |
Output is correct |
47 |
Correct |
169 ms |
2788 KB |
Output is correct |
48 |
Correct |
170 ms |
3052 KB |
Output is correct |
49 |
Correct |
163 ms |
2888 KB |
Output is correct |
50 |
Correct |
207 ms |
2796 KB |
Output is correct |
51 |
Correct |
40 ms |
2260 KB |
Output is correct |
52 |
Correct |
190 ms |
3348 KB |
Output is correct |
53 |
Correct |
244 ms |
3056 KB |
Output is correct |
54 |
Correct |
229 ms |
3232 KB |
Output is correct |
55 |
Correct |
247 ms |
3916 KB |
Output is correct |
56 |
Correct |
198 ms |
3232 KB |
Output is correct |
57 |
Correct |
235 ms |
3952 KB |
Output is correct |
58 |
Correct |
270 ms |
3276 KB |
Output is correct |
59 |
Correct |
235 ms |
3524 KB |
Output is correct |
60 |
Correct |
77 ms |
2260 KB |
Output is correct |
61 |
Correct |
237 ms |
3600 KB |
Output is correct |
62 |
Correct |
241 ms |
3796 KB |
Output is correct |
63 |
Correct |
211 ms |
3820 KB |
Output is correct |
64 |
Correct |
221 ms |
3952 KB |
Output is correct |
65 |
Correct |
203 ms |
2664 KB |
Output is correct |
66 |
Correct |
201 ms |
2812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2260 KB |
Output is correct |
2 |
Correct |
6 ms |
2260 KB |
Output is correct |
3 |
Correct |
2 ms |
2256 KB |
Output is correct |
4 |
Correct |
4 ms |
2260 KB |
Output is correct |
5 |
Correct |
10 ms |
2260 KB |
Output is correct |
6 |
Correct |
7 ms |
2260 KB |
Output is correct |
7 |
Correct |
6 ms |
2260 KB |
Output is correct |
8 |
Correct |
9 ms |
2260 KB |
Output is correct |
9 |
Correct |
8 ms |
2248 KB |
Output is correct |
10 |
Correct |
21 ms |
2308 KB |
Output is correct |
11 |
Correct |
23 ms |
2260 KB |
Output is correct |
12 |
Correct |
21 ms |
2284 KB |
Output is correct |
13 |
Correct |
20 ms |
2260 KB |
Output is correct |
14 |
Correct |
20 ms |
2300 KB |
Output is correct |
15 |
Correct |
30 ms |
2260 KB |
Output is correct |
16 |
Correct |
23 ms |
2300 KB |
Output is correct |
17 |
Correct |
19 ms |
2252 KB |
Output is correct |
18 |
Correct |
19 ms |
2304 KB |
Output is correct |
19 |
Correct |
22 ms |
2260 KB |
Output is correct |
20 |
Correct |
21 ms |
2260 KB |
Output is correct |
21 |
Correct |
43 ms |
2304 KB |
Output is correct |
22 |
Correct |
72 ms |
2304 KB |
Output is correct |
23 |
Correct |
44 ms |
2312 KB |
Output is correct |
24 |
Correct |
63 ms |
2320 KB |
Output is correct |
25 |
Correct |
65 ms |
2352 KB |
Output is correct |
26 |
Correct |
65 ms |
2352 KB |
Output is correct |
27 |
Correct |
65 ms |
2360 KB |
Output is correct |
28 |
Correct |
65 ms |
2356 KB |
Output is correct |
29 |
Correct |
73 ms |
2356 KB |
Output is correct |
30 |
Correct |
67 ms |
2304 KB |
Output is correct |
31 |
Correct |
66 ms |
2352 KB |
Output is correct |
32 |
Correct |
78 ms |
2368 KB |
Output is correct |
33 |
Correct |
66 ms |
2360 KB |
Output is correct |
34 |
Correct |
65 ms |
2308 KB |
Output is correct |
35 |
Correct |
71 ms |
2356 KB |
Output is correct |
36 |
Correct |
68 ms |
2320 KB |
Output is correct |
37 |
Correct |
158 ms |
2692 KB |
Output is correct |
38 |
Correct |
130 ms |
2664 KB |
Output is correct |
39 |
Correct |
160 ms |
2672 KB |
Output is correct |
40 |
Correct |
186 ms |
2796 KB |
Output is correct |
41 |
Correct |
188 ms |
2824 KB |
Output is correct |
42 |
Correct |
196 ms |
2772 KB |
Output is correct |
43 |
Correct |
160 ms |
3092 KB |
Output is correct |
44 |
Correct |
169 ms |
3104 KB |
Output is correct |
45 |
Correct |
163 ms |
3148 KB |
Output is correct |
46 |
Correct |
172 ms |
2416 KB |
Output is correct |
47 |
Correct |
169 ms |
2788 KB |
Output is correct |
48 |
Correct |
170 ms |
3052 KB |
Output is correct |
49 |
Correct |
163 ms |
2888 KB |
Output is correct |
50 |
Correct |
207 ms |
2796 KB |
Output is correct |
51 |
Correct |
40 ms |
2260 KB |
Output is correct |
52 |
Correct |
190 ms |
3348 KB |
Output is correct |
53 |
Correct |
244 ms |
3056 KB |
Output is correct |
54 |
Correct |
229 ms |
3232 KB |
Output is correct |
55 |
Correct |
247 ms |
3916 KB |
Output is correct |
56 |
Correct |
198 ms |
3232 KB |
Output is correct |
57 |
Correct |
235 ms |
3952 KB |
Output is correct |
58 |
Correct |
270 ms |
3276 KB |
Output is correct |
59 |
Correct |
235 ms |
3524 KB |
Output is correct |
60 |
Correct |
77 ms |
2260 KB |
Output is correct |
61 |
Correct |
237 ms |
3600 KB |
Output is correct |
62 |
Correct |
241 ms |
3796 KB |
Output is correct |
63 |
Correct |
211 ms |
3820 KB |
Output is correct |
64 |
Correct |
221 ms |
3952 KB |
Output is correct |
65 |
Correct |
203 ms |
2664 KB |
Output is correct |
66 |
Correct |
201 ms |
2812 KB |
Output is correct |
67 |
Correct |
278 ms |
3552 KB |
Output is correct |
68 |
Correct |
81 ms |
2260 KB |
Output is correct |
69 |
Correct |
396 ms |
5472 KB |
Output is correct |
70 |
Correct |
378 ms |
4308 KB |
Output is correct |
71 |
Correct |
335 ms |
4152 KB |
Output is correct |
72 |
Correct |
339 ms |
3200 KB |
Output is correct |
73 |
Correct |
337 ms |
3196 KB |
Output is correct |
74 |
Correct |
351 ms |
5692 KB |
Output is correct |
75 |
Correct |
379 ms |
4920 KB |
Output is correct |
76 |
Correct |
354 ms |
5744 KB |
Output is correct |
77 |
Correct |
350 ms |
5804 KB |
Output is correct |