제출 #439237

#제출 시각아이디문제언어결과실행 시간메모리
439237LastRoninBootfall (IZhO17_bootfall)C++14
65 / 100
818 ms1012 KiB
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define si short int
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pill pair<ll,ll>
#define f first
#define s second
#define pilc pair<ll,char>
#define all(a) (a).begin(),(a).end()
#define rep(s,e,step) for(int i = (s); i < (e) ; i += step)
#define vrep(s,e,step) for(int j = (s); j < (e) ; j += step)
#define ex exit(0) 
#define sz(a) (a).size()
#define triple pair<pill, ll>
#define pinode pair<node*, node*>
#define quadra pair<pill, pill>
#define ld long double
using namespace std;
 
const ll N = 350 + 1;
const ll M = 1e4 + 10;
const ll big = 1e17;
const ll hsh2 = 1964325029;
const long long mod = 1e9 + 7;
const long double EPS = 1e-10;
const ll block = 1e7;
const ll shift = 2e3;
const ld pi = acos(-1.0);

ll sum = 0;
ll n;
ll a[N];

int main() {
	speed;
	cin >> n;
	ll sum = 0;
	for(int i = 1; i <= n; i++)
		cin >> a[i], sum += a[i];
	const ll p = sum + 1;
	bitset<N * N> x, ans, tr;
	for(int i = 1; i <= sum; i++)
		ans[i] = 1;
	if(sum % 2 != 0)
		cout << 0, ex;
   	x = 0;
	x[0] = 1;
	for(int i = 1; i <= n; i++)
		x = x|(x<<a[i]);
	if(!x[sum/2])
		cout << 0, ex;	
	for(int i = 1; i <= n; i++) {
		x = tr = 0;
		x[0] = 1;
		ll sum2 = sum - a[i];
		for(int j = 1; j <= n; j++) 
			if(j != i)
				x = x|(x<<a[j]);
		for(int j = 1; j <= sum2; j++) {
			if(x[j]) {
				ll p = sum2 - j;
				ll z = j - p;
				if(z <= 0)continue;
				tr[z] = 1;	
			}
		}
		ans &= tr;
	}
	vector<int> answ;
	for(int i = 1; i <= sum ; i++)
		if(ans[i])
			answ.pb(i);
	cout << answ.size() << '\n';
	for(auto u : answ)
		cout << u << " ";
	cout << '\n';	
				
}
/*
*/  

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

bootfall.cpp: In function 'int main()':
bootfall.cpp:43:11: warning: unused variable 'p' [-Wunused-variable]
   43 |  const ll p = sum + 1;
      |           ^
#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...