#include<bits/stdc++.h>
using namespace std;
#define int long long
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
#define all(x) x.begin(), x.end()
#define ins insert
#define pb push_back
#define F first
#define S second
const int N = 250100, M = 500;
int dp[N];
int a[501], cnt[N], sum;
void solve(){
int n;
cin>>n;
dp[0] = 1;
for(int i = 1; i <= n; i++){
cin>>a[i];
for(int j = N - 1; j >= a[i]; j--){
dp[j] += dp[j - a[i]];
}
sum += a[i];
}
if(sum % 2 == 1 || dp[sum / 2] == 0){
cout<<"0";
return;
}
for(int i = 1; i <= n; i++){
for(int j = a[i]; j < N; j++){
dp[j] -= dp[j - a[i]];
}
for(int j = 0; j <= sum - a[i]; j++){
if(!dp[j]) continue;
int x = j, y = sum - a[i] - j;
cnt[abs(x - y)]++;
}
for(int j = N - 1; j >= a[i]; j--){
dp[j] += dp[j - a[i]];
}
}
vector<int>ans;
for(int i = 0; i <= 250000; i++){
if(cnt[i] == n * 2) ans.pb(i);
}
cout<<ans.size()<<'\n';
for(auto it : ans) cout<<it<<' ';
}
main(){
ios_base :: sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
//cin>>t;
for(int i = 1; i <= t; i++){
//cout<<"Case "<<i<<": ";
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
bootfall.cpp:49:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
49 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |