//Bismillahi-rahmani-rahim
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef map <int, int> mii;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const int inf=1e9;
#define azdar priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>
#define Lebap ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
#define pf push_front
#define pk pop_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
//#include <conio.h>
#include <climits>
const int N = 500*500;
int n, a[509], dp[N+509][509], dp1[N+509], cnt[N+509];
int main(){
Lebap;
cin>>n;
int sum=0;
for(int i=1;i<=n;i++) cin>>a[i], sum += a[i];
for(int i=0;i<=n;i++) dp[0][i]=1;
if(sum%2!=0) return cout << 0 , 0;
for(int i=1;i<=N;i++){
for(int j=1;j<=n;j++){
dp[i][j] = dp[i][j-1];
if(i>=a[j]){
dp[i][j] += dp[i-a[j]][j-1];
}
}
}
if(dp[sum/2]==0) return cout << 0 , 0;
for(int i=1;i<=n;i++){
memset( dp1, 0, sizeof(dp1) );
for(int j=0;j<=N;j++){
dp1[j] += dp[j][n];
dp1[j+a[i]] -= dp1[j];
}
for(int j=0;j<=N;j++){
if(sum-a[i]-j>=0 && (sum-a[i]+j)%2==0 && dp1[(sum-a[i]+j)/2]!=0) cnt[j]++;
}
}
vector <int> ans;
for(int i=1;i<=N;i++) if( cnt[i] == n ) ans.pb(i);
cout << ans.size() << endl;
for(int i=0;i<ans.size();i++) cout << ans[i] << " ";
return 0;
}
Compilation message
bootfall.cpp: In function 'int main()':
bootfall.cpp:66:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<ans.size();i++) cout << ans[i] << " ";
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
1840 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
1840 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
1840 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
1840 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
1840 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
1840 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |