Submission #168072

#TimeUsernameProblemLanguageResultExecution timeMemory
168072GurbanBootfall (IZhO17_bootfall)C++14
0 / 100
51 ms1400 KiB
#include <bits/stdc++.h>

#define pb push_back
#define ss second
#define ff first
#define N 250000
#define inf 1000000009
#define ll long long
#define mid(a,b) (a+b)/2

using namespace std;

int n,a[N],sum,sum1,l;
int c[509][N],s[509][N],dp[509][N];
map <int,int> m;
vector <int> v;

int main()
{
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		scanf("%d",&a[i]);
		sum += a[i];
		s[0][i] = 1;
		c[0][i] = 1;
	}
	c[0][0] = 1;
	s[0][0] = 1;
	sum1 = ceil(double(sum)/2.0);
	for(int i = 1;i <= sum;i++)
		for(int j = 1;j <= n;j++)
			if(c[i][j - 1] or (i >= a[j] and c[i - a[j]][j - 1] > 0))
				c[i][j] = 1;
	for(int i = 1;i <= sum;i++){
		for(int j = n;j >= 1;j--){
			l = n - j + 1;
			if(s[i][l - 1] or (i >= a[j] and s[i - a[j]][l - 1] > 0))
				s[i][l] = 1;
		}
	}
	if(sum % 2 == 1 or (c[sum1][n] == 0))
		return cout << 0,0;
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= sum;j++){
			for(int k = 1;k <= sum;k++){
				if(c[j][i - 1])
					dp[i][j] = 1;
				if(s[k][n - i])
					dp[i][k] = 1;
				if(c[j][i - 1] and s[k][n - i]){
					dp[i][j + k] = 1;
				}
			}
		}
	}
	for(int i = 1;i <= n;i++)
		dp[i][0] = 1;
	for(int i = 1;i <= n;i++){
		for(int j = 1;j < sum;j++){
			l = sum - a[i] + j;
			if(l % 2 == 1) continue;
			if(dp[i][l / 2 - j])
				m[j]++;
		}
	}
	for(auto i : m)
		if(i.ss == n) v.pb(i.ff);
	printf("%d\n",v.size());
	for(auto i : v)
		printf("%d\n",i);
}

Compilation message (stderr)

bootfall.cpp: In function 'int main()':
bootfall.cpp:68:24: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
  printf("%d\n",v.size());
                ~~~~~~~~^
bootfall.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
bootfall.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a[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...