Submission #333624

# Submission time Handle Problem Language Result Execution time Memory
333624 2020-12-07T08:59:39 Z tengiz05 Bootfall (IZhO17_bootfall) C++17
0 / 100
30 ms 1132 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
const int mod = 1e9+7, N = 35;
int msb(int val){return sizeof(int)*8-__builtin_clzll(val);}
int a[N], n, m, k, rev[N];
bool dp[N*N][N];
bool sp[N*N][N];
bool calc(int x){
	int i, j;
	bool pos = true;
	for(k=0;k<=n;k++){
		memset(dp, 0, sizeof(dp));
		swap(a[k], x);
		dp[0][0] = 1;
		int sum = 0;
		for(i=1;i<=n;i++)sum += a[i];
		for(i=1;i<=sum;i++){
			for(j=1;j<=n;j++){
				dp[i][j] = dp[i][j-1];
				if(i-a[j] >= 0)dp[i][j] |= dp[i-a[j]][j-1];
			}
		}
		if(!dp[sum/2][n] || sum%2!=0)pos = false;
		swap(a[k], x);
	}
	return pos;
}
void solve(int test_case){
	int i, j;
	cin >> n;
	int sum = 0;
	for(i=1;i<=n;i++){
		cin >> a[i];
		sum += a[i];
	}
	vector<int> ans;
	for(i=1;i<=sum;i++){
		if(calc(i))ans.pb(i);
	}
	cout << ans.size() << '\n';
	for(auto x : ans)cout << x << ' ';
	cout << '\n';
	return;
}

signed main(){
	FASTIO;
#define MULTITEST 0
#if MULTITEST
	int ___T;
	cin >> ___T;
	for(int T_CASE = 1; T_CASE <= ___T; T_CASE++)
		solve(T_CASE);
#else
	solve(1);
#endif
	return 0;
}


Compilation message

bootfall.cpp: In function 'void solve(long long int)':
bootfall.cpp:38:9: warning: unused variable 'j' [-Wunused-variable]
   38 |  int i, j;
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Runtime error 30 ms 1132 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Runtime error 30 ms 1132 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Runtime error 30 ms 1132 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Runtime error 30 ms 1132 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Runtime error 30 ms 1132 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Runtime error 30 ms 1132 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -