제출 #1265781

#제출 시각아이디문제언어결과실행 시간메모리
1265781PlayVoltzBootfall (IZhO17_bootfall)C++20
100 / 100
284 ms5812 KiB
#include <cstdio>
#include <stdio.h>
#include <stdbool.h>
#include <iostream>
#include <map>
#include <vector>
#include <climits>
#include <stack>
#include <string>
#include <queue>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <cctype>
#include <bitset>
#include <iomanip>
#include <cstring>
#include <numeric>
#include <cassert>
using namespace std;
 
#define int long long
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, k=0;
	cin>>n;
	vector<int> vect(n);
	for (int i=0; i<n; ++i)cin>>vect[i], k+=vect[i];
	vector<int> dp(k+1, 0), cc(k+1, 0);
	dp[0]=1;
	for (int i=0; i<n; ++i)for (int j=k; j>=vect[i]; --j)dp[j]+=dp[j-vect[i]];
	if (k%2||!dp[k/2]){
		cout<<0;
		return 0;
	}
	for (int i=0; i<n; ++i){
		for (int j=vect[i]; j<=k; ++j)dp[j]-=dp[j-vect[i]];
		k-=vect[i];
		for (int j=0; j<=k/2; ++j)if (dp[j])++cc[k-2*j];
		k+=vect[i];
		for (int j=k; j>=vect[i]; --j)dp[j]+=dp[j-vect[i]];
	}
	vector<int> ans;
	for (int i=0; i<=k; ++i)if (cc[i]==n)ans.pb(i);
	cout<<ans.size()<<"\n";
	for (auto a:ans)cout<<a<<" ";
}
#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...