#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define bug cout << "bug" << endl
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define pll pair <ll, ll>
#define pii pair <int, int>
#define triple pair <pair <ll, ll> , ll>
#define ull unsigned long long
#define ld long double
#define pinode pair <node*, node*>
const ll INF = 9e18 + 5;
const ll inf = 1e9 + 5;
const ll N = 5e2 + 5;
const ll shift = 2e6;
const ll mod = 1e9 + 7;
const ll M = 500 * 500 + 5;
const ll LOG = 21;
const ll sp = 263;
const ll block = 500;
const double eps = 1e-10;
ll n, a[N], dp[M], acc = 0, cnt[M];
int main(){
speed;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
acc += a[i];
}
dp[0] = 1;
for(int i = 1; i <= n; i++){
for(int sum = M - 5; sum >= a[i]; sum--){
dp[sum] += dp[sum - a[i]];
}
}
if(acc % 2 != 0 || dp[acc / 2] == 0){
cout << 0 << endl;
return 0;
}
for(int i = 1; i <= n; i++){
for(int sum = a[i]; sum <= M - 5; sum++){
dp[sum] -= dp[sum - a[i]];
}
acc -= a[i];
for(int sum = 0; sum <= M - 5; sum++){
if(dp[sum] > 0){
int ost = acc - sum;
if(ost - sum < 0)
continue;
cnt[ost - sum]++;
}
}
acc += a[i];
for(int sum = M - 5; sum >= a[i]; sum--){
dp[sum] += dp[sum - a[i]];
}
}
vector <int> ans;;
for(int i = 0; i <= M - 5; i++){
if(cnt[i] == n)
ans.pb(i);
}
cout << ans.size() << endl;
for(auto to : ans)
cout << to << " ";
}
/*
%I64d
%I64d
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2252 KB |
Output is correct |
2 |
Correct |
7 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
6 ms |
2252 KB |
Output is correct |
5 |
Correct |
9 ms |
2288 KB |
Output is correct |
6 |
Correct |
7 ms |
2252 KB |
Output is correct |
7 |
Correct |
6 ms |
2252 KB |
Output is correct |
8 |
Correct |
11 ms |
2248 KB |
Output is correct |
9 |
Correct |
8 ms |
2252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2252 KB |
Output is correct |
2 |
Correct |
7 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
6 ms |
2252 KB |
Output is correct |
5 |
Correct |
9 ms |
2288 KB |
Output is correct |
6 |
Correct |
7 ms |
2252 KB |
Output is correct |
7 |
Correct |
6 ms |
2252 KB |
Output is correct |
8 |
Correct |
11 ms |
2248 KB |
Output is correct |
9 |
Correct |
8 ms |
2252 KB |
Output is correct |
10 |
Correct |
19 ms |
2276 KB |
Output is correct |
11 |
Correct |
20 ms |
2252 KB |
Output is correct |
12 |
Correct |
19 ms |
2252 KB |
Output is correct |
13 |
Correct |
19 ms |
2280 KB |
Output is correct |
14 |
Correct |
19 ms |
2280 KB |
Output is correct |
15 |
Correct |
20 ms |
2280 KB |
Output is correct |
16 |
Correct |
21 ms |
2284 KB |
Output is correct |
17 |
Correct |
14 ms |
2284 KB |
Output is correct |
18 |
Correct |
16 ms |
2252 KB |
Output is correct |
19 |
Correct |
18 ms |
2252 KB |
Output is correct |
20 |
Correct |
20 ms |
2284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2252 KB |
Output is correct |
2 |
Correct |
7 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
6 ms |
2252 KB |
Output is correct |
5 |
Correct |
9 ms |
2288 KB |
Output is correct |
6 |
Correct |
7 ms |
2252 KB |
Output is correct |
7 |
Correct |
6 ms |
2252 KB |
Output is correct |
8 |
Correct |
11 ms |
2248 KB |
Output is correct |
9 |
Correct |
8 ms |
2252 KB |
Output is correct |
10 |
Correct |
19 ms |
2276 KB |
Output is correct |
11 |
Correct |
20 ms |
2252 KB |
Output is correct |
12 |
Correct |
19 ms |
2252 KB |
Output is correct |
13 |
Correct |
19 ms |
2280 KB |
Output is correct |
14 |
Correct |
19 ms |
2280 KB |
Output is correct |
15 |
Correct |
20 ms |
2280 KB |
Output is correct |
16 |
Correct |
21 ms |
2284 KB |
Output is correct |
17 |
Correct |
14 ms |
2284 KB |
Output is correct |
18 |
Correct |
16 ms |
2252 KB |
Output is correct |
19 |
Correct |
18 ms |
2252 KB |
Output is correct |
20 |
Correct |
20 ms |
2284 KB |
Output is correct |
21 |
Correct |
39 ms |
2280 KB |
Output is correct |
22 |
Incorrect |
55 ms |
2248 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2252 KB |
Output is correct |
2 |
Correct |
7 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
6 ms |
2252 KB |
Output is correct |
5 |
Correct |
9 ms |
2288 KB |
Output is correct |
6 |
Correct |
7 ms |
2252 KB |
Output is correct |
7 |
Correct |
6 ms |
2252 KB |
Output is correct |
8 |
Correct |
11 ms |
2248 KB |
Output is correct |
9 |
Correct |
8 ms |
2252 KB |
Output is correct |
10 |
Correct |
19 ms |
2276 KB |
Output is correct |
11 |
Correct |
20 ms |
2252 KB |
Output is correct |
12 |
Correct |
19 ms |
2252 KB |
Output is correct |
13 |
Correct |
19 ms |
2280 KB |
Output is correct |
14 |
Correct |
19 ms |
2280 KB |
Output is correct |
15 |
Correct |
20 ms |
2280 KB |
Output is correct |
16 |
Correct |
21 ms |
2284 KB |
Output is correct |
17 |
Correct |
14 ms |
2284 KB |
Output is correct |
18 |
Correct |
16 ms |
2252 KB |
Output is correct |
19 |
Correct |
18 ms |
2252 KB |
Output is correct |
20 |
Correct |
20 ms |
2284 KB |
Output is correct |
21 |
Correct |
39 ms |
2280 KB |
Output is correct |
22 |
Incorrect |
55 ms |
2248 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2252 KB |
Output is correct |
2 |
Correct |
7 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
6 ms |
2252 KB |
Output is correct |
5 |
Correct |
9 ms |
2288 KB |
Output is correct |
6 |
Correct |
7 ms |
2252 KB |
Output is correct |
7 |
Correct |
6 ms |
2252 KB |
Output is correct |
8 |
Correct |
11 ms |
2248 KB |
Output is correct |
9 |
Correct |
8 ms |
2252 KB |
Output is correct |
10 |
Correct |
19 ms |
2276 KB |
Output is correct |
11 |
Correct |
20 ms |
2252 KB |
Output is correct |
12 |
Correct |
19 ms |
2252 KB |
Output is correct |
13 |
Correct |
19 ms |
2280 KB |
Output is correct |
14 |
Correct |
19 ms |
2280 KB |
Output is correct |
15 |
Correct |
20 ms |
2280 KB |
Output is correct |
16 |
Correct |
21 ms |
2284 KB |
Output is correct |
17 |
Correct |
14 ms |
2284 KB |
Output is correct |
18 |
Correct |
16 ms |
2252 KB |
Output is correct |
19 |
Correct |
18 ms |
2252 KB |
Output is correct |
20 |
Correct |
20 ms |
2284 KB |
Output is correct |
21 |
Correct |
39 ms |
2280 KB |
Output is correct |
22 |
Incorrect |
55 ms |
2248 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2252 KB |
Output is correct |
2 |
Correct |
7 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
6 ms |
2252 KB |
Output is correct |
5 |
Correct |
9 ms |
2288 KB |
Output is correct |
6 |
Correct |
7 ms |
2252 KB |
Output is correct |
7 |
Correct |
6 ms |
2252 KB |
Output is correct |
8 |
Correct |
11 ms |
2248 KB |
Output is correct |
9 |
Correct |
8 ms |
2252 KB |
Output is correct |
10 |
Correct |
19 ms |
2276 KB |
Output is correct |
11 |
Correct |
20 ms |
2252 KB |
Output is correct |
12 |
Correct |
19 ms |
2252 KB |
Output is correct |
13 |
Correct |
19 ms |
2280 KB |
Output is correct |
14 |
Correct |
19 ms |
2280 KB |
Output is correct |
15 |
Correct |
20 ms |
2280 KB |
Output is correct |
16 |
Correct |
21 ms |
2284 KB |
Output is correct |
17 |
Correct |
14 ms |
2284 KB |
Output is correct |
18 |
Correct |
16 ms |
2252 KB |
Output is correct |
19 |
Correct |
18 ms |
2252 KB |
Output is correct |
20 |
Correct |
20 ms |
2284 KB |
Output is correct |
21 |
Correct |
39 ms |
2280 KB |
Output is correct |
22 |
Incorrect |
55 ms |
2248 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |