제출 #168455

#제출 시각아이디문제언어결과실행 시간메모리
168455GurbanBootfall (IZhO17_bootfall)C++14
100 / 100
429 ms3944 KiB
#include <bits/stdc++.h>

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

using namespace std;

int n,a[509],sum,dp[N],s;
vector <int> v,ans;

const int mod = 1e9+7;

int main()
{
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		scanf("%d",&a[i]);
		sum += a[i];
	}
	dp[0] = 1;
	for(int i = 1;i <= n;i++)
		for(int j = sum;j >= 0;j--)
			dp[j + a[i]] += dp[j];
		
	if(sum % 2 == 1 or  dp[sum / 2] == 0)
		return cout << 0,0;
	
	
	for(int i = 1;i <= sum;i++)
		ans.pb(i);
	
	for(int i = 1;i <= n;i++){
		for(int j = a[i];j <= sum;j++)
			dp[j] -= dp[j - a[i]];
		
		for(auto j : ans){
			s = sum - a[i] + j;
			if(s % 2 == 0 and s / 2 - j >= 0 and dp[s / 2 - j])
				v.pb(j);
		}
		
		ans.clear();
		ans = v;
		v.clear();
		
		for(int j = sum;j >= a[i];j--)
			dp[j] += dp[j - a[i]];
	}
	printf("%d\n",ans.size());
	for(auto i : ans) printf("%d\n",i);
}

컴파일 시 표준 에러 (stderr) 메시지

bootfall.cpp: In function 'int main()':
bootfall.cpp:54:26: 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",ans.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...