#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll MAX_N = 505;
const ll MAX_N2 = 255025;
ll sum,n,dp[MAX_N2],cnt[MAX_N2],a[MAX_N];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n;
for(ll i=0; i<n; i++)
{
cin>>a[i];
sum+=a[i];
}
dp[0] = 1;
for(ll i=0; i<n; i++)
{
for(ll s=MAX_N2-a[i]-1; s>=0; s--)
{
dp[s+a[i]] += dp[s];
}
}
if(sum%2 != 0 || dp[sum/2] == 0)
{
cout<<0<<endl;
return 0;
}
for(ll i=0; i<n; i++) /// ignore i-th
{
for(ll s=0; s+a[i]<MAX_N2; s++)
{
dp[s+a[i]] -= dp[s];
}
sum-=a[i];
for(ll x0=0; x0<MAX_N2 && x0<=sum; x0++)
{
if((sum+x0)%2 == 0)
{
if(dp[(sum+x0)/2] > 0)
{
cnt[x0]++;
}
}
}
sum+=a[i];
for(ll s=MAX_N2-a[i]-1; s>=0; s--)
{
dp[s+a[i]] += dp[s];
}
}
vector<ll> res;
for(ll x0=0; x0<MAX_N2; x0++)
{
if(cnt[x0] == n)
{
res.push_back(x0);
}
}
cout<<res.size()<<endl;
for(auto x: res) cout<<x<<" ";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2252 KB |
Output is correct |
2 |
Correct |
5 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
4 ms |
2252 KB |
Output is correct |
5 |
Correct |
8 ms |
2328 KB |
Output is correct |
6 |
Correct |
6 ms |
2316 KB |
Output is correct |
7 |
Correct |
5 ms |
2252 KB |
Output is correct |
8 |
Correct |
8 ms |
2252 KB |
Output is correct |
9 |
Correct |
7 ms |
2252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2252 KB |
Output is correct |
2 |
Correct |
5 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
4 ms |
2252 KB |
Output is correct |
5 |
Correct |
8 ms |
2328 KB |
Output is correct |
6 |
Correct |
6 ms |
2316 KB |
Output is correct |
7 |
Correct |
5 ms |
2252 KB |
Output is correct |
8 |
Correct |
8 ms |
2252 KB |
Output is correct |
9 |
Correct |
7 ms |
2252 KB |
Output is correct |
10 |
Correct |
16 ms |
2324 KB |
Output is correct |
11 |
Correct |
17 ms |
2252 KB |
Output is correct |
12 |
Correct |
16 ms |
2320 KB |
Output is correct |
13 |
Correct |
17 ms |
2312 KB |
Output is correct |
14 |
Correct |
15 ms |
2312 KB |
Output is correct |
15 |
Correct |
16 ms |
2312 KB |
Output is correct |
16 |
Correct |
18 ms |
2308 KB |
Output is correct |
17 |
Correct |
11 ms |
2312 KB |
Output is correct |
18 |
Correct |
13 ms |
2320 KB |
Output is correct |
19 |
Correct |
15 ms |
2320 KB |
Output is correct |
20 |
Correct |
15 ms |
2252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2252 KB |
Output is correct |
2 |
Correct |
5 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
4 ms |
2252 KB |
Output is correct |
5 |
Correct |
8 ms |
2328 KB |
Output is correct |
6 |
Correct |
6 ms |
2316 KB |
Output is correct |
7 |
Correct |
5 ms |
2252 KB |
Output is correct |
8 |
Correct |
8 ms |
2252 KB |
Output is correct |
9 |
Correct |
7 ms |
2252 KB |
Output is correct |
10 |
Correct |
16 ms |
2324 KB |
Output is correct |
11 |
Correct |
17 ms |
2252 KB |
Output is correct |
12 |
Correct |
16 ms |
2320 KB |
Output is correct |
13 |
Correct |
17 ms |
2312 KB |
Output is correct |
14 |
Correct |
15 ms |
2312 KB |
Output is correct |
15 |
Correct |
16 ms |
2312 KB |
Output is correct |
16 |
Correct |
18 ms |
2308 KB |
Output is correct |
17 |
Correct |
11 ms |
2312 KB |
Output is correct |
18 |
Correct |
13 ms |
2320 KB |
Output is correct |
19 |
Correct |
15 ms |
2320 KB |
Output is correct |
20 |
Correct |
15 ms |
2252 KB |
Output is correct |
21 |
Correct |
30 ms |
2252 KB |
Output is correct |
22 |
Incorrect |
34 ms |
2332 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2252 KB |
Output is correct |
2 |
Correct |
5 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
4 ms |
2252 KB |
Output is correct |
5 |
Correct |
8 ms |
2328 KB |
Output is correct |
6 |
Correct |
6 ms |
2316 KB |
Output is correct |
7 |
Correct |
5 ms |
2252 KB |
Output is correct |
8 |
Correct |
8 ms |
2252 KB |
Output is correct |
9 |
Correct |
7 ms |
2252 KB |
Output is correct |
10 |
Correct |
16 ms |
2324 KB |
Output is correct |
11 |
Correct |
17 ms |
2252 KB |
Output is correct |
12 |
Correct |
16 ms |
2320 KB |
Output is correct |
13 |
Correct |
17 ms |
2312 KB |
Output is correct |
14 |
Correct |
15 ms |
2312 KB |
Output is correct |
15 |
Correct |
16 ms |
2312 KB |
Output is correct |
16 |
Correct |
18 ms |
2308 KB |
Output is correct |
17 |
Correct |
11 ms |
2312 KB |
Output is correct |
18 |
Correct |
13 ms |
2320 KB |
Output is correct |
19 |
Correct |
15 ms |
2320 KB |
Output is correct |
20 |
Correct |
15 ms |
2252 KB |
Output is correct |
21 |
Correct |
30 ms |
2252 KB |
Output is correct |
22 |
Incorrect |
34 ms |
2332 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2252 KB |
Output is correct |
2 |
Correct |
5 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
4 ms |
2252 KB |
Output is correct |
5 |
Correct |
8 ms |
2328 KB |
Output is correct |
6 |
Correct |
6 ms |
2316 KB |
Output is correct |
7 |
Correct |
5 ms |
2252 KB |
Output is correct |
8 |
Correct |
8 ms |
2252 KB |
Output is correct |
9 |
Correct |
7 ms |
2252 KB |
Output is correct |
10 |
Correct |
16 ms |
2324 KB |
Output is correct |
11 |
Correct |
17 ms |
2252 KB |
Output is correct |
12 |
Correct |
16 ms |
2320 KB |
Output is correct |
13 |
Correct |
17 ms |
2312 KB |
Output is correct |
14 |
Correct |
15 ms |
2312 KB |
Output is correct |
15 |
Correct |
16 ms |
2312 KB |
Output is correct |
16 |
Correct |
18 ms |
2308 KB |
Output is correct |
17 |
Correct |
11 ms |
2312 KB |
Output is correct |
18 |
Correct |
13 ms |
2320 KB |
Output is correct |
19 |
Correct |
15 ms |
2320 KB |
Output is correct |
20 |
Correct |
15 ms |
2252 KB |
Output is correct |
21 |
Correct |
30 ms |
2252 KB |
Output is correct |
22 |
Incorrect |
34 ms |
2332 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2252 KB |
Output is correct |
2 |
Correct |
5 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
4 ms |
2252 KB |
Output is correct |
5 |
Correct |
8 ms |
2328 KB |
Output is correct |
6 |
Correct |
6 ms |
2316 KB |
Output is correct |
7 |
Correct |
5 ms |
2252 KB |
Output is correct |
8 |
Correct |
8 ms |
2252 KB |
Output is correct |
9 |
Correct |
7 ms |
2252 KB |
Output is correct |
10 |
Correct |
16 ms |
2324 KB |
Output is correct |
11 |
Correct |
17 ms |
2252 KB |
Output is correct |
12 |
Correct |
16 ms |
2320 KB |
Output is correct |
13 |
Correct |
17 ms |
2312 KB |
Output is correct |
14 |
Correct |
15 ms |
2312 KB |
Output is correct |
15 |
Correct |
16 ms |
2312 KB |
Output is correct |
16 |
Correct |
18 ms |
2308 KB |
Output is correct |
17 |
Correct |
11 ms |
2312 KB |
Output is correct |
18 |
Correct |
13 ms |
2320 KB |
Output is correct |
19 |
Correct |
15 ms |
2320 KB |
Output is correct |
20 |
Correct |
15 ms |
2252 KB |
Output is correct |
21 |
Correct |
30 ms |
2252 KB |
Output is correct |
22 |
Incorrect |
34 ms |
2332 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |