Submission #851696

#TimeUsernameProblemLanguageResultExecution timeMemory
851696stdfloatBootfall (IZhO17_bootfall)C++17
100 / 100
265 ms5828 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

int32_t main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);

	int n;
	cin >> n;

	int sm = 0;
	vector<int> a(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		sm += a[i];
	}

	vector<int> dp(sm + 1, 0); dp[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = sm - a[i]; j >= 0; j--) {
			dp[j + a[i]] += dp[j];
		}
	}
	if ((sm & 1) || !dp[(sm>>1)]) {
		return cout << 0, 0;
	}

	vector<int> cnt(sm + 1, 0);
	for (int i = 1; i <= n; i++) {
		int x = sm - a[i];
		for (int j = 0; j <= sm - a[i]; j++) {
			dp[j + a[i]] -= dp[j];
		}

		for (int j = ((x + 1)>>1); j <= x; j++) {
			cnt[(j<<1) - x] += !!dp[j];
		}

		for (int j = sm - a[i]; j >= 0; j--) {
			dp[j + a[i]] += dp[j];
		}
	}

	vector<int> v;
	for (int i = 0; i <= sm; i++) {
		if (cnt[i] == n) v.push_back(i);
	}

	cout << (int)v.size() << "\n";
	for (auto i : v) {
		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...