답안 #93033

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
93033 2019-01-06T10:08:52 Z emil_physmath Bootfall (IZhO17_bootfall) C++17
0 / 100
86 ms 59260 KB
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <bitset>
#include <cstring>
#include <vector>
using namespace std;
const int MAXN=300;

int a[MAXN];
bitset<270*270+1> sums[MAXN];

bitset<270*270+1> AllPossSums(int arr[], int n);
int main()
{
	int n, sum=0;
	cin>>n;
	for (int i=0; i<n; i++)
		cin>>a[i];
	for (int i=0; i<n; i++)
	{
		sum+=a[i];
		swap(a[i], a[n-1]);
		sums[i]=AllPossSums(a, n-1);
		swap(a[i], a[n-1]);
	}
	if (sum%2 || !AllPossSums(a, n)[sum/2])
	{
		cout<<"0\n";
		return 0;
	}
	vector<int> ans;
	for (int x=1; x<=sum; x++)
	{
		bool isAns=true;
		for (int i=0; i<n; i++)
		{
			if ((sum-a[i]+x)%2) {
				isAns=false;
				break;
			}
			if (!sums[i][(sum-a[i]+x)/2-x]) {
				isAns=false;
				break;
			}
		}
		if (isAns)
			ans.push_back(x);
	}
	cout<<ans.size()<<'\n';
	for (int i=0; i<ans.size(); i++)
		cout<<ans[i]<<' ';
	cout<<'\n';

	char I;
	cin >> I;
	return 0;
}

bool dp[MAXN][100000];
bitset<270*270+1> AllPossSums(int arr[], int n)
{
	int sum=0;
	for (int i=0; i<n; i++)
		sum+=arr[i];
	memset(dp, 0, sizeof(dp));
	for (int i=0; i<=n; i++)
		dp[i][0]=true;
	for (int i=1; i<=n; i++)
	{
		dp[i][arr[i-1]]=true;
		for (int j=1; j<=sum; j++)
		{
			if (dp[i-1][j]==true)
			{
				dp[i][j]=true;
				dp[i][j+arr[i-1]]=true;
			}
		}
	}
	bitset<270*270+1> res;
	for (int j=0; j<=sum; j++)
		if (dp[n][j]==true)
			res[j]=true;
	return res;
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:51:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0; i<ans.size(); i++)
                ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 86 ms 59260 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 86 ms 59260 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 86 ms 59260 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 86 ms 59260 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 86 ms 59260 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 86 ms 59260 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -