제출 #340221

#제출 시각아이디문제언어결과실행 시간메모리
340221TosicBootfall (IZhO17_bootfall)C++14
100 / 100
319 ms2924 KiB
#include <bits/stdc++.h>
#define maxn 510
using namespace std;

int n, a[maxn], kS[maxn*maxn], isOk[maxn*maxn], ans, sum;


int main(){
	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; ++i){
		cin >> a[i];
		sum += a[i];
	}
		kS[0] = 1;
	for(int i = 0; i < n; ++i){
		for(int j = sum-a[i]; j >= 0; --j){
			kS[j+a[i]] += kS[j];
		}
	}if(sum%2 or !kS[sum/2]){
		cout <<0;
		return 0;
	}

	for(int i = 0; i < n; ++i){
		int tmp = sum-a[i];
		for(int j = a[i]; j <= sum; ++j){
			kS[j] -= kS[j-a[i]];
            //cerr << kS[j] << ' ';
			if(2*j - tmp > 0 and kS[j]){
				isOk[2*j - tmp]++;
				if(isOk[-tmp+j*2] == n){
					++ans;
				}
			}
		}
		for(int j = 1; j < a[i]; ++j){
			if(2*j - tmp > 0 and kS[j]){
				isOk[2*j - tmp]++;
				if(isOk[-tmp+j*2] == n){
					++ans;
				}
			}
		}
		cerr << '\n';
		for(int j = sum-a[i]; j >= 0; --j){
			kS[j+a[i]] += kS[j];
		}
	}
	cout << ans << '\n';
	for(int i = 1; i <= sum; ++i){
		if(isOk[i] == n){
			cout << i << ' ';
		}
	}
}
#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...