#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
const ll maxn = 5e2 + 1, maxm = 4e3 + 1, maxk = 61;
const ll inf = 1000000000, mod = inf + 7, mod2 = 998244353;
const ll pa = 31, block = 400;
using namespace std;
ll n, x, y;
ll a[maxn], dp[maxn * maxn], cnt[maxn * maxn], cnt2[maxn * maxn];
int main(){
// ios_base::sync_with_stdio(false);
// cin.tie(0), cout.tie(0);
cin >> n;
dp[0] = 1;
for (int i = 1; i <= n; ++i){
cin >> a[i];
for (int j = x; j >= 0; --j){
if (dp[j] > 0){
dp[j + a[i]] += dp[j];
}
}
x += a[i];
}
if (x % 2 != 0 || (x % 2 == 0 && dp[x / 2] == 0)){
cout << 0 << '\n';
return 0;
}
for (int i = 1; i <= maxn * maxn - 1; ++i){
cnt[i] = 1;
}
for (int i = 1; i <= n; ++i){
y = x - a[i];
for (int j = 0; j <= maxn * maxn - 1; ++j){
if (j + a[i] <= maxn * maxn - 1){
dp[j + a[i]] -= dp[j];
// dp[j + a[i]] = max(0ll, dp[j + a[i]]);
}
}
for (int j = 0; j <= maxn * maxn - 1; ++j){
if (dp[j] > 0){
ll f = j, s = y - j;
ll rz = abs(f - s);
if (cnt[rz] == 1){
cnt2[rz] = 1;
}
}
}
for (int j = maxn * maxn - 1; j >= 0; --j){
if (j + a[i] <= maxn * maxn - 1){
dp[j + a[i]] += dp[j];
}
}
for (int j = 1; j <= maxn * maxn - 1; ++j){
cnt[j] = cnt2[j];
cnt2[j] = 0;
}
}
vector<int> v;
for (int i = 1; i <= maxn * maxn - 1; ++i){
if (cnt[i] > 0){
v.pb(i);
}
}
cout << v.size() << '\n';
for (auto it : v){
cout << it << " ";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
6192 KB |
Output is correct |
2 |
Correct |
9 ms |
6092 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
10 ms |
6220 KB |
Output is correct |
5 |
Correct |
11 ms |
6124 KB |
Output is correct |
6 |
Correct |
9 ms |
6132 KB |
Output is correct |
7 |
Correct |
9 ms |
6092 KB |
Output is correct |
8 |
Correct |
12 ms |
6184 KB |
Output is correct |
9 |
Correct |
12 ms |
6092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
6192 KB |
Output is correct |
2 |
Correct |
9 ms |
6092 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
10 ms |
6220 KB |
Output is correct |
5 |
Correct |
11 ms |
6124 KB |
Output is correct |
6 |
Correct |
9 ms |
6132 KB |
Output is correct |
7 |
Correct |
9 ms |
6092 KB |
Output is correct |
8 |
Correct |
12 ms |
6184 KB |
Output is correct |
9 |
Correct |
12 ms |
6092 KB |
Output is correct |
10 |
Correct |
32 ms |
6092 KB |
Output is correct |
11 |
Correct |
32 ms |
6172 KB |
Output is correct |
12 |
Correct |
26 ms |
6092 KB |
Output is correct |
13 |
Correct |
22 ms |
6184 KB |
Output is correct |
14 |
Correct |
23 ms |
6180 KB |
Output is correct |
15 |
Correct |
24 ms |
6176 KB |
Output is correct |
16 |
Correct |
29 ms |
6220 KB |
Output is correct |
17 |
Correct |
16 ms |
6188 KB |
Output is correct |
18 |
Correct |
20 ms |
6188 KB |
Output is correct |
19 |
Correct |
22 ms |
6104 KB |
Output is correct |
20 |
Correct |
29 ms |
6172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
6192 KB |
Output is correct |
2 |
Correct |
9 ms |
6092 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
10 ms |
6220 KB |
Output is correct |
5 |
Correct |
11 ms |
6124 KB |
Output is correct |
6 |
Correct |
9 ms |
6132 KB |
Output is correct |
7 |
Correct |
9 ms |
6092 KB |
Output is correct |
8 |
Correct |
12 ms |
6184 KB |
Output is correct |
9 |
Correct |
12 ms |
6092 KB |
Output is correct |
10 |
Correct |
32 ms |
6092 KB |
Output is correct |
11 |
Correct |
32 ms |
6172 KB |
Output is correct |
12 |
Correct |
26 ms |
6092 KB |
Output is correct |
13 |
Correct |
22 ms |
6184 KB |
Output is correct |
14 |
Correct |
23 ms |
6180 KB |
Output is correct |
15 |
Correct |
24 ms |
6176 KB |
Output is correct |
16 |
Correct |
29 ms |
6220 KB |
Output is correct |
17 |
Correct |
16 ms |
6188 KB |
Output is correct |
18 |
Correct |
20 ms |
6188 KB |
Output is correct |
19 |
Correct |
22 ms |
6104 KB |
Output is correct |
20 |
Correct |
29 ms |
6172 KB |
Output is correct |
21 |
Correct |
46 ms |
6164 KB |
Output is correct |
22 |
Incorrect |
68 ms |
6092 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
6192 KB |
Output is correct |
2 |
Correct |
9 ms |
6092 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
10 ms |
6220 KB |
Output is correct |
5 |
Correct |
11 ms |
6124 KB |
Output is correct |
6 |
Correct |
9 ms |
6132 KB |
Output is correct |
7 |
Correct |
9 ms |
6092 KB |
Output is correct |
8 |
Correct |
12 ms |
6184 KB |
Output is correct |
9 |
Correct |
12 ms |
6092 KB |
Output is correct |
10 |
Correct |
32 ms |
6092 KB |
Output is correct |
11 |
Correct |
32 ms |
6172 KB |
Output is correct |
12 |
Correct |
26 ms |
6092 KB |
Output is correct |
13 |
Correct |
22 ms |
6184 KB |
Output is correct |
14 |
Correct |
23 ms |
6180 KB |
Output is correct |
15 |
Correct |
24 ms |
6176 KB |
Output is correct |
16 |
Correct |
29 ms |
6220 KB |
Output is correct |
17 |
Correct |
16 ms |
6188 KB |
Output is correct |
18 |
Correct |
20 ms |
6188 KB |
Output is correct |
19 |
Correct |
22 ms |
6104 KB |
Output is correct |
20 |
Correct |
29 ms |
6172 KB |
Output is correct |
21 |
Correct |
46 ms |
6164 KB |
Output is correct |
22 |
Incorrect |
68 ms |
6092 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
6192 KB |
Output is correct |
2 |
Correct |
9 ms |
6092 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
10 ms |
6220 KB |
Output is correct |
5 |
Correct |
11 ms |
6124 KB |
Output is correct |
6 |
Correct |
9 ms |
6132 KB |
Output is correct |
7 |
Correct |
9 ms |
6092 KB |
Output is correct |
8 |
Correct |
12 ms |
6184 KB |
Output is correct |
9 |
Correct |
12 ms |
6092 KB |
Output is correct |
10 |
Correct |
32 ms |
6092 KB |
Output is correct |
11 |
Correct |
32 ms |
6172 KB |
Output is correct |
12 |
Correct |
26 ms |
6092 KB |
Output is correct |
13 |
Correct |
22 ms |
6184 KB |
Output is correct |
14 |
Correct |
23 ms |
6180 KB |
Output is correct |
15 |
Correct |
24 ms |
6176 KB |
Output is correct |
16 |
Correct |
29 ms |
6220 KB |
Output is correct |
17 |
Correct |
16 ms |
6188 KB |
Output is correct |
18 |
Correct |
20 ms |
6188 KB |
Output is correct |
19 |
Correct |
22 ms |
6104 KB |
Output is correct |
20 |
Correct |
29 ms |
6172 KB |
Output is correct |
21 |
Correct |
46 ms |
6164 KB |
Output is correct |
22 |
Incorrect |
68 ms |
6092 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
6192 KB |
Output is correct |
2 |
Correct |
9 ms |
6092 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
10 ms |
6220 KB |
Output is correct |
5 |
Correct |
11 ms |
6124 KB |
Output is correct |
6 |
Correct |
9 ms |
6132 KB |
Output is correct |
7 |
Correct |
9 ms |
6092 KB |
Output is correct |
8 |
Correct |
12 ms |
6184 KB |
Output is correct |
9 |
Correct |
12 ms |
6092 KB |
Output is correct |
10 |
Correct |
32 ms |
6092 KB |
Output is correct |
11 |
Correct |
32 ms |
6172 KB |
Output is correct |
12 |
Correct |
26 ms |
6092 KB |
Output is correct |
13 |
Correct |
22 ms |
6184 KB |
Output is correct |
14 |
Correct |
23 ms |
6180 KB |
Output is correct |
15 |
Correct |
24 ms |
6176 KB |
Output is correct |
16 |
Correct |
29 ms |
6220 KB |
Output is correct |
17 |
Correct |
16 ms |
6188 KB |
Output is correct |
18 |
Correct |
20 ms |
6188 KB |
Output is correct |
19 |
Correct |
22 ms |
6104 KB |
Output is correct |
20 |
Correct |
29 ms |
6172 KB |
Output is correct |
21 |
Correct |
46 ms |
6164 KB |
Output is correct |
22 |
Incorrect |
68 ms |
6092 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |