제출 #36063

#제출 시각아이디문제언어결과실행 시간메모리
36063UncleGrandpa925Bootfall (IZhO17_bootfall)C++14
13 / 100
6 ms4128 KiB
/*input
4
1 3 1 5
*/
#include <bits/stdc++.h>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define N 505
#define bit(x,y) ((x>>y)&1LL)
#define na(x) (#x) << ":" << x
ostream& operator << (ostream &os, vector<int>&x) {
	for (int i = 0; i < x.size(); i++) os << x[i] << sp;
	return os;
}
ostream& operator << (ostream &os, pair<int, int> x) {
	cout << x.fi << sp << x.se << sp;
	return os;
}
ostream& operator << (ostream &os, vector<pair<int, int> >&x) {
	for (int i = 0; i < x.size(); i++) os << x[i] << endl;
	return os;
}
const int mod = 1e9 + 7;

int n;
int a[N];
int f[250005];
int sum = 0;
int mark[250005];
vector<int> order;

void add(int x) {
	for (int i = sum; i >= 0; i--) {
		f[i + x] += f[i];
		if (f[i + x] >= mod) f[i + x] -= mod;
	}
	sum += x;
}

void sub(int x) {
	for (int i = 0; i <= sum; i++) {
		f[i + x] += (mod - f[i]);
		if (f[i + x] >= mod) f[i + x] -= mod;
	}
	sum -= x;
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	f[0] = 1;
	for (int i = 1; i <= n; i++) cin >> a[i], add(a[i]);
	if (sum % 2 || f[sum / 2] == 0) {
		cout << 0 << endl;
		return 0;
	}
	for (int i = 1; i <= n; i++) {
		sub(a[i]);
		int sta = 1; if (sum % 2 == 0) sta++;
		for (int j = sta; j <= sum; j += 2) {
			if (f[(sum + j) / 2 - j])
				mark[j]++;
		}
		add(a[i]);
	}
	for (int i = 1; i <= sum; i++) if (mark[i] == n) order.push_back(i);
	cout << order.size() << endl;
	cout << order << endl;
}

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

bootfall.cpp: In function 'std::ostream& operator<<(std::ostream&, std::vector<int>&)':
bootfall.cpp:16:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < x.size(); i++) os << x[i] << sp;
                    ^
bootfall.cpp: In function 'std::ostream& operator<<(std::ostream&, std::vector<std::pair<int, int> >&)':
bootfall.cpp:24:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < x.size(); i++) os << x[i] << endl;
                    ^
#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...