Submission #438160

# Submission time Handle Problem Language Result Execution time Memory
438160 2021-06-27T17:02:17 Z lulwpop Bootfall (IZhO17_bootfall) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define all(X) X.begin(), X.end()
#define sz(x) (int)x.size()
#define fr first
#define sc second
#define endl '\n'

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int maxn = 1e6 + 10;
const int maxa = 1e6;
const int inf = 2e9;
const ll INF = 1e18;
const ll mod = 1e9 + 7;
const int block = 350;

int main () 
{
	ios_base::sync_with_stdio(0); cin.tie();
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/
	int n; cin >> n;
	vector <int> a (n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	bitset <25100> st;
	int sum = 0;
	st[0] = 1;
	for (int i = 0; i < n; i++) {
		st |= (st << a[i]);
		sum += a[i];
	}
	if ((sum & 1)) {
		cout << 0;
		return 0;
	} else if (!st[sum >> 1]) {
		cout << 0;
		return 0;
	}

	vector <bitset <n * 500>> t (n);
	for (int sk = 0; sk < n; sk++) {
		t[sk][0] = 1;
		for (int j = 0; j < n; j++) {
			if (j != sk) {
				t[sk] |= (t[sk] << a[j]);
			}
		}
	}
	vector <int> ans;
	for (int i = 1; i <= n * 500; i++) {
		vector <bitset <n * 500>> tt = t;
		sum += i;
		bool ok = true;
		for (int j = 0; j < n; j++) {
			tt[j] |= (tt[j] << i);
			sum -= a[j];
			if ((sum & 1)) {
				ok = false;
				sum += a[j];
				break;
			} else if (!tt[j][sum >> 1]) {
				ok = false;
				sum += a[j];
				break;
			} else {
				sum += a[j];
			}
		}
		sum -= i;
		if (ok) ans.push_back(i);
	}
	cout << sz(ans) << endl;
	for (auto i : ans) {
		cout << i << " ";
	}
	return 0;
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:49:22: error: the value of 'n' is not usable in a constant expression
   49 |  vector <bitset <n * 500>> t (n);
      |                      ^~~
bootfall.cpp:29:6: note: 'int n' is not const
   29 |  int n; cin >> n;
      |      ^
bootfall.cpp:49:22: error: the value of 'n' is not usable in a constant expression
   49 |  vector <bitset <n * 500>> t (n);
      |                      ^~~
bootfall.cpp:29:6: note: 'int n' is not const
   29 |  int n; cin >> n;
      |      ^
bootfall.cpp:49:20: note: in template argument for type 'long unsigned int'
   49 |  vector <bitset <n * 500>> t (n);
      |                  ~~^~~~~
bootfall.cpp:49:25: error: template argument 1 is invalid
   49 |  vector <bitset <n * 500>> t (n);
      |                         ^~
bootfall.cpp:49:25: error: template argument 2 is invalid
bootfall.cpp:51:4: error: invalid types 'int[int]' for array subscript
   51 |   t[sk][0] = 1;
      |    ^
bootfall.cpp:54:6: error: invalid types 'int[int]' for array subscript
   54 |     t[sk] |= (t[sk] << a[j]);
      |      ^
bootfall.cpp:54:16: error: invalid types 'int[int]' for array subscript
   54 |     t[sk] |= (t[sk] << a[j]);
      |                ^
bootfall.cpp:60:23: error: the value of 'n' is not usable in a constant expression
   60 |   vector <bitset <n * 500>> tt = t;
      |                       ^~~
bootfall.cpp:29:6: note: 'int n' is not const
   29 |  int n; cin >> n;
      |      ^
bootfall.cpp:60:23: error: the value of 'n' is not usable in a constant expression
   60 |   vector <bitset <n * 500>> tt = t;
      |                       ^~~
bootfall.cpp:29:6: note: 'int n' is not const
   29 |  int n; cin >> n;
      |      ^
bootfall.cpp:60:21: note: in template argument for type 'long unsigned int'
   60 |   vector <bitset <n * 500>> tt = t;
      |                   ~~^~~~~
bootfall.cpp:60:26: error: template argument 1 is invalid
   60 |   vector <bitset <n * 500>> tt = t;
      |                          ^~
bootfall.cpp:60:26: error: template argument 2 is invalid
bootfall.cpp:64:6: error: invalid types 'int[int]' for array subscript
   64 |    tt[j] |= (tt[j] << i);
      |      ^
bootfall.cpp:64:16: error: invalid types 'int[int]' for array subscript
   64 |    tt[j] |= (tt[j] << i);
      |                ^
bootfall.cpp:70:18: error: invalid types 'int[int]' for array subscript
   70 |    } else if (!tt[j][sum >> 1]) {
      |                  ^