답안 #91478

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
91478 2018-12-27T16:34:36 Z davitmarg Bootfall (IZhO17_bootfall) C++17
0 / 100
5 ms 504 KB
/*
DEATH-MATCH
Davit-Marg
*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iterator>
#include <ctype.h>
#include <stdlib.h>  
#include <fstream>  
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
using namespace std;

LL n,a[5000006],cant[5000006];
LL sum,sm;
vector<LL> ans;
LL dp[5000006];

void add(LL k)
{
	sum += k;
	for (LL j = sum; j >= 0; j--)
		dp[j + k] += dp[j];
}

void rem(LL k)
{
	for (LL i = 0; i <= sum; i++)
		dp[i + k] -= dp[i];
	sum -= k;
}

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

	for (LL i = 0; i < n; i++)
		add(a[i]);

	if (sm % 2==1 || dp[sm / 2] == 0)
	{
		cout << 0 << endl;
		return 0;
	}
	for (LL i = 0; i < n; i++)
	{
		rem(a[i]);
		for (LL j = 0; j <= sm; j++)
		{
			assert(dp[(sum + j) / 2]<0);
			if ((sum + j) % 2 == 1 || dp[(sum + j) / 2] == 0)
				cant[j] = 1;
		}
		add(a[i]);
	}
	for (LL j = 0; j <= sm; j++)
		if (!cant[j])
			ans.PB(j);
	
	cout << ans.size() << endl;
	for (LL i = 0; i < ans.size(); i++)
		cout << ans[i] << " ";
	cout << endl;
	return 0;
}

Compilation message

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