제출 #545563

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
template<typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}

const int md=1e9+7;
int n,a[505],dp[505*505],cc[505*505],ndp[505*505];

void chkadd(int&x,int y){x+=y; if(x>md) x-=md;}
void chksub(int&x,int y){x-=y; if(x<0) x+=md;}

int main(){
	scanf("%d",&n);
	dp[0]=1;
	int s=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		for(int j=505*505-1;j>=a[i];j--) chkadd(dp[j],dp[j-a[i]]);
		s+=a[i];
	}
	if((s&1)||!dp[s/2]){printf("0"); return 0;}
	for(int i=1;i<=n;i++){
		for(int j=0;j<505*505;j++) ndp[j]=dp[j];
		for(int j=0;j<505*505-a[i];j++) chksub(ndp[j+a[i]],ndp[j]);
		for(int j=0;j<505*505;j++){
			int ns=s-a[i]+j;
			if(ns/2-j>=0&&ns%2==0&&ndp[ns/2-j]) cc[j]++;
		}
	}
	vector<int> ans;
	for(int i=0;i<505*505;i++) if(cc[i]==n) ans.pb(i);
	printf("%d\n",ans.size());
	for(int i=0;i<ans.size();i++) printf("%d ",ans[i]);
	return 0;
}

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

bootfall.cpp: In function 'int main()':
bootfall.cpp:44:11: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
   44 |  printf("%d\n",ans.size());
      |          ~^    ~~~~~~~~~~
      |           |            |
      |           int          std::vector<int>::size_type {aka long unsigned int}
      |          %ld
bootfall.cpp:45:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |  for(int i=0;i<ans.size();i++) printf("%d ",ans[i]);
      |              ~^~~~~~~~~~~
bootfall.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
bootfall.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |   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...