#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;
int 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 == 1 || 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)
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 |
5 ms |
1228 KB |
Output is correct |
2 |
Correct |
5 ms |
1228 KB |
Output is correct |
3 |
Correct |
2 ms |
1228 KB |
Output is correct |
4 |
Correct |
4 ms |
1228 KB |
Output is correct |
5 |
Correct |
8 ms |
1212 KB |
Output is correct |
6 |
Correct |
6 ms |
1304 KB |
Output is correct |
7 |
Correct |
5 ms |
1228 KB |
Output is correct |
8 |
Correct |
8 ms |
1308 KB |
Output is correct |
9 |
Correct |
7 ms |
1300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1228 KB |
Output is correct |
2 |
Correct |
5 ms |
1228 KB |
Output is correct |
3 |
Correct |
2 ms |
1228 KB |
Output is correct |
4 |
Correct |
4 ms |
1228 KB |
Output is correct |
5 |
Correct |
8 ms |
1212 KB |
Output is correct |
6 |
Correct |
6 ms |
1304 KB |
Output is correct |
7 |
Correct |
5 ms |
1228 KB |
Output is correct |
8 |
Correct |
8 ms |
1308 KB |
Output is correct |
9 |
Correct |
7 ms |
1300 KB |
Output is correct |
10 |
Correct |
17 ms |
1228 KB |
Output is correct |
11 |
Correct |
20 ms |
1300 KB |
Output is correct |
12 |
Correct |
18 ms |
1296 KB |
Output is correct |
13 |
Correct |
16 ms |
1300 KB |
Output is correct |
14 |
Correct |
16 ms |
1228 KB |
Output is correct |
15 |
Correct |
18 ms |
1228 KB |
Output is correct |
16 |
Correct |
20 ms |
1228 KB |
Output is correct |
17 |
Correct |
12 ms |
1228 KB |
Output is correct |
18 |
Correct |
18 ms |
1228 KB |
Output is correct |
19 |
Correct |
16 ms |
1228 KB |
Output is correct |
20 |
Correct |
17 ms |
1356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1228 KB |
Output is correct |
2 |
Correct |
5 ms |
1228 KB |
Output is correct |
3 |
Correct |
2 ms |
1228 KB |
Output is correct |
4 |
Correct |
4 ms |
1228 KB |
Output is correct |
5 |
Correct |
8 ms |
1212 KB |
Output is correct |
6 |
Correct |
6 ms |
1304 KB |
Output is correct |
7 |
Correct |
5 ms |
1228 KB |
Output is correct |
8 |
Correct |
8 ms |
1308 KB |
Output is correct |
9 |
Correct |
7 ms |
1300 KB |
Output is correct |
10 |
Correct |
17 ms |
1228 KB |
Output is correct |
11 |
Correct |
20 ms |
1300 KB |
Output is correct |
12 |
Correct |
18 ms |
1296 KB |
Output is correct |
13 |
Correct |
16 ms |
1300 KB |
Output is correct |
14 |
Correct |
16 ms |
1228 KB |
Output is correct |
15 |
Correct |
18 ms |
1228 KB |
Output is correct |
16 |
Correct |
20 ms |
1228 KB |
Output is correct |
17 |
Correct |
12 ms |
1228 KB |
Output is correct |
18 |
Correct |
18 ms |
1228 KB |
Output is correct |
19 |
Correct |
16 ms |
1228 KB |
Output is correct |
20 |
Correct |
17 ms |
1356 KB |
Output is correct |
21 |
Incorrect |
40 ms |
1304 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1228 KB |
Output is correct |
2 |
Correct |
5 ms |
1228 KB |
Output is correct |
3 |
Correct |
2 ms |
1228 KB |
Output is correct |
4 |
Correct |
4 ms |
1228 KB |
Output is correct |
5 |
Correct |
8 ms |
1212 KB |
Output is correct |
6 |
Correct |
6 ms |
1304 KB |
Output is correct |
7 |
Correct |
5 ms |
1228 KB |
Output is correct |
8 |
Correct |
8 ms |
1308 KB |
Output is correct |
9 |
Correct |
7 ms |
1300 KB |
Output is correct |
10 |
Correct |
17 ms |
1228 KB |
Output is correct |
11 |
Correct |
20 ms |
1300 KB |
Output is correct |
12 |
Correct |
18 ms |
1296 KB |
Output is correct |
13 |
Correct |
16 ms |
1300 KB |
Output is correct |
14 |
Correct |
16 ms |
1228 KB |
Output is correct |
15 |
Correct |
18 ms |
1228 KB |
Output is correct |
16 |
Correct |
20 ms |
1228 KB |
Output is correct |
17 |
Correct |
12 ms |
1228 KB |
Output is correct |
18 |
Correct |
18 ms |
1228 KB |
Output is correct |
19 |
Correct |
16 ms |
1228 KB |
Output is correct |
20 |
Correct |
17 ms |
1356 KB |
Output is correct |
21 |
Incorrect |
40 ms |
1304 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1228 KB |
Output is correct |
2 |
Correct |
5 ms |
1228 KB |
Output is correct |
3 |
Correct |
2 ms |
1228 KB |
Output is correct |
4 |
Correct |
4 ms |
1228 KB |
Output is correct |
5 |
Correct |
8 ms |
1212 KB |
Output is correct |
6 |
Correct |
6 ms |
1304 KB |
Output is correct |
7 |
Correct |
5 ms |
1228 KB |
Output is correct |
8 |
Correct |
8 ms |
1308 KB |
Output is correct |
9 |
Correct |
7 ms |
1300 KB |
Output is correct |
10 |
Correct |
17 ms |
1228 KB |
Output is correct |
11 |
Correct |
20 ms |
1300 KB |
Output is correct |
12 |
Correct |
18 ms |
1296 KB |
Output is correct |
13 |
Correct |
16 ms |
1300 KB |
Output is correct |
14 |
Correct |
16 ms |
1228 KB |
Output is correct |
15 |
Correct |
18 ms |
1228 KB |
Output is correct |
16 |
Correct |
20 ms |
1228 KB |
Output is correct |
17 |
Correct |
12 ms |
1228 KB |
Output is correct |
18 |
Correct |
18 ms |
1228 KB |
Output is correct |
19 |
Correct |
16 ms |
1228 KB |
Output is correct |
20 |
Correct |
17 ms |
1356 KB |
Output is correct |
21 |
Incorrect |
40 ms |
1304 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1228 KB |
Output is correct |
2 |
Correct |
5 ms |
1228 KB |
Output is correct |
3 |
Correct |
2 ms |
1228 KB |
Output is correct |
4 |
Correct |
4 ms |
1228 KB |
Output is correct |
5 |
Correct |
8 ms |
1212 KB |
Output is correct |
6 |
Correct |
6 ms |
1304 KB |
Output is correct |
7 |
Correct |
5 ms |
1228 KB |
Output is correct |
8 |
Correct |
8 ms |
1308 KB |
Output is correct |
9 |
Correct |
7 ms |
1300 KB |
Output is correct |
10 |
Correct |
17 ms |
1228 KB |
Output is correct |
11 |
Correct |
20 ms |
1300 KB |
Output is correct |
12 |
Correct |
18 ms |
1296 KB |
Output is correct |
13 |
Correct |
16 ms |
1300 KB |
Output is correct |
14 |
Correct |
16 ms |
1228 KB |
Output is correct |
15 |
Correct |
18 ms |
1228 KB |
Output is correct |
16 |
Correct |
20 ms |
1228 KB |
Output is correct |
17 |
Correct |
12 ms |
1228 KB |
Output is correct |
18 |
Correct |
18 ms |
1228 KB |
Output is correct |
19 |
Correct |
16 ms |
1228 KB |
Output is correct |
20 |
Correct |
17 ms |
1356 KB |
Output is correct |
21 |
Incorrect |
40 ms |
1304 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |