Submission #522920

#TimeUsernameProblemLanguageResultExecution timeMemory
522920Sanzhar23Bootfall (IZhO17_bootfall)C++14
28 / 100
105 ms452 KiB
#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 = 1e2 + 5;
const ll shift = 2e6;
const ll mod = 1e9 + 7;
const ll M = 10000 + 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 >= 0; sum--){
			if(sum - a[i] >= 0 && dp[sum - a[i]])
				dp[sum] = 1;
		}
	}
	if(acc % 2 != 0 || dp[acc / 2] == 0){
		cout << 0 << endl;
		return 0;
	}
	for(int i = 1; i <= n; i++){
		memset(dp, 0, sizeof(dp));
		dp[0] = 1;
		acc -= a[i];
		for(int j = 1; j <= n; j++){
			if(j == i)
				continue;
			for(int sum = M - 5; sum >= 0; sum--){
				if(sum - a[j] >= 0 && dp[sum - a[j]])
					dp[sum] = 1;
			}
		}
		for(int sum = 0; sum <= M - 5; sum++){
			if(dp[sum]){
				int ost = acc - sum;
				if(ost - sum < 0)
					continue;
				cnt[ost - sum]++;
			}
		}
		acc += 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
*/ 
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...