제출 #35047

#제출 시각아이디문제언어결과실행 시간메모리
35047model_codeBootfall (IZhO17_bootfall)C++11
65 / 100
1000 ms17928 KiB
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <bitset>
#define f first
#define s second
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define vi vector <int>
#define ld long double
#define pii pair<int, int>
#define y1 sda
using namespace std;    
const int N = 502, mod = int(1e9)  + 7; 

int n,a[N];

int s;

bitset <N*N> dp[N];

vector <int> ans;
bool used[N];

int main () {
	scanf("%d",&n);
	bool odd = 0, even = 0;
	for(int i = 1; i <= n; i++){
		scanf("%d",&a[i]);
		s += a[i];
		if(a[i] & 1) odd = 1;
		else even = 1;
	}
	if(odd && even){
		printf("0");
		return 0;
	}
	dp[0][0] = 1;
	for(int i = 1; i <= n; i++){
		dp[0] = (dp[0] | (dp[0] << a[i]));
	}
	if((s & 1) || dp[0][s >> 1] == 0){
		printf("0");
		return 0;
	}
	for(int i = 1; i <= n; i++){
		if(used[a[i]]) continue;
		used[a[i]] = 1;
		dp[a[i]][0] = 1;
		for(int j = 1; j <= n; j++) if(i != j){
			dp[a[i]] |= (dp[a[i]] << a[j]);
		}
	}
	for(int x = 1; x <= s; x++){
		bool ok = 1;
		for(int i = 1; i <= n; i++){
			if((s - a[i] + x) & 1){
				ok = 0;
				break;
			}
			if(dp[a[i]][(s - a[i] + x) >> 1] == 0){
				ok = 0;
				break;
			}
		}
		if(ok){
			ans.pb(x);
		}
	}
	printf("%d\n", int(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:84:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < ans.size(); i++){
                   ^
bootfall.cpp:39:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
bootfall.cpp:42:20: 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...