제출 #173511

#제출 시각아이디문제언어결과실행 시간메모리
173511AllMightBootfall (IZhO17_bootfall)C++14
13 / 100
1077 ms736 KiB
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>

using namespace std;

const int N = 502;

int n;
int a[N];
int cnt[N * N];
vector <int> v;

void check(int ind)
{
	vector <bool> knp(N * N, false);
	knp[0] = true;
	priority_queue <int> pq[2];
	pq[0].push(0);

	for (int i = 0, f = 0; i < n; i++, f = 1 - f) {
		if (i == ind) {
			f = 1 - f;
			continue;
		}

		while (!pq[f].empty()) {
			int tp = pq[f].top();
			pq[f].pop();

			pq[1 - f].push(tp);
			if (!knp[tp + a[i]])
				pq[1 - f].push(tp + a[i]);

			knp[tp + a[i]] = true;
		}
	}
	
	int sum;
	if (pq[0].empty())
		sum = pq[1].top();
	else
		sum = pq[0].top();
	
	for (int i = 0; 2 * i < sum; i++) {
		if (!knp[i])	continue;
		int ans = sum - 2 * i;
		cnt[ans]++;
		if (ind == 0)
			v.push_back(ans);
	}
}

int main()
{
	ios_base::sync_with_stdio(false);

	cin >> n;
	vector <bool> knp(N * N, false);
	knp[0] = true;
	priority_queue <int> pq[2];
	pq[0].push(0);
	for (int i = 0, f = 0; i < n; i++, f = 1 - f) {
		cin >> a[i];
		while (!pq[f].empty()) {
			int tp = pq[f].top();
			pq[f].pop();

			pq[1 - f].push(tp);
			if (!knp[tp + a[i]])
				pq[1 - f].push(tp + a[i]);
			
			knp[tp + a[i]] = true;
		}
	}
	int sum;
	if (pq[0].empty())
		sum = pq[1].top();
	else
		sum = pq[0].top();
	if (sum % 2 || !knp[sum / 2]) {
		cout << "0\n";
		return 0;
	}

	for (int i = 0; i < n; i++)
		check(i);

	vector <int> ans;
	for (int i = 0; i < v.size(); i++)
		if (cnt[v[i]] == n)
			ans.push_back(v[i]);

	sort(ans.begin(), ans.end());
	cout << ans.size() << endl;
	for (int i = 0; i < ans.size(); i++)
		cout << ans[i] << ' ';
	cout << endl;

	return 0;
}

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

bootfall.cpp: In function 'int main()':
bootfall.cpp:92:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < v.size(); i++)
                  ~~^~~~~~~~~~
bootfall.cpp:98:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < ans.size(); 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...