답안 #172946

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
172946 2020-01-02T19:09:55 Z LinusTorvaldsFan Money (IZhO17_money) C++14
0 / 100
0 ms 632 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
 
using namespace std;
 
const int maxn=501;
const int maxc=501;
const int maxw=maxc*maxn;
bitset<maxn*maxc>available[maxn];
bitset<maxn*maxc>used[maxn];
 
 
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	vector<int>a(n);
	int sum=0;
	for(int i=0;i<n;i++) {
		cin>>a[i];
		sum+=a[i];
	}
	for(int i=0;i<=n;i++){
		if(i>0) {
			available[i]=available[i-1];
			available[i]|=available[i]<<a[i-1];
		}
		else available[i][0]=true;
	}
	for(int i=0;i<=n;i++){
		for(int j=i+1;j<n;j++){
			available[i]|=available[i]<<a[j];
		}
	}
	if(sum&1){
		cout<<0;
		return 0;
	}
	if(!available[n][sum>>1]){
		cout<<0;
		return 0;
	}
	
	for(int i=0;i<n;i++){
		if(((sum-a[i]) & 1) != ((sum-a[0])&1)){
			cout<<0;
			return 0;
		}
	}
	
	vector<int>ans;
	for(int x=(sum-a[0])&1;x<=maxw;x+=2){
		bool ok=true;	
		for(int i=0;i<n;i++){
			int nsum=sum-a[i]+x;
			if(!available[i][nsum>>1]){
				ok=false;
				break;
			}
		}
		if(ok){
			ans.push_back(x);
		}
	}
	cout<<ans.size()<<"\n";
	for(auto& x:ans)cout<<x<<" ";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 632 KB Output isn't correct
2 Halted 0 ms 0 KB -