#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#include <bits/stdc++.h>
// #define int long long
#define pb push_back
#define ui unsigned int
#define ld long double
#define pl pair<long long int, long long int>
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ff first
#define ss second
#define sz size()
#define all(x) x.begin(), x.end()
using namespace std;
const int maxn = 3e5 + 11;
// const int inf = 1e18 + 1;
// const int mod = 1e9 + 7;
// // const int mod = 998244353;
// const int dx[] = {-1, 0, 0, 1, -1, -1, 1, 1};
// const int dy[] = {0, -1, 1 , 0, -1, 1, -1, 1};
// const double eps = 1e-10;
void solve() {
int n;
cin >> n;
int a[n + 2];
for(int i = 0; i < n; i++) {
cin >> a[ i ];
}
if(n <= 12) {
n++;
vector<int> v;
for(int x = 1; x <= 1000; x++) {
a[n - 1] = x;
bool bl = true;
for(int j = 0; j < n; j++) {
bool fl = false;
for(int mask = 0; mask < (1 << n); mask++) {
int cnt1 = 0, cnt2 = 0;
for(int i = 0; i < n; i++) {
if(i == j) {
continue;
}
if(mask & (1 << i)) {
cnt1 += a[ i ];
}
else {
cnt2 += a[ i ];
}
}
if(cnt1 == cnt2) {
fl = true;
break;
}
}
if(!fl) {
bl = false;
break;
}
}
if(bl) {
v.pb( x );
}
}
cout << v.sz << '\n';
for(auto it : v) {
cout << it << ' ';
}
return;
}
if(n <= 30) {
int cnt = 0;
int cntt1 = 0, cntt2 = 0;
for(int i = 0; i < n; i++) {
cnt += a[ i ];
if(a[ i ] % 2 == 1) {
cntt1++;
}
else {
cntt2++;
}
}
if((cntt1 && cntt2) || (cntt1 && cnt % 2 == 1)) {
cout << 0;
return;
}
n++;
vector<int> v;
int mp[301];
for(int x = 1; x <= 600; x++) {
if((cntt1 && x % 2 == 0) || (cntt2 && x % 2 == 1)) {
continue;
}
cnt += x;
a[n - 1] = x;
bool bl = true;
for(int j = 0; j < n; j++) {
cnt -= a[ j ];
for(int k = 0; k <= 300; k++) {
mp[ k ] = 0;
}
bool fl = false;
for(int mask = 0; mask < (1 << (n / 2)); mask++) {
int cnt1 = 0;
for(int i = 0; i < n / 2; i++) {
if(i == j) {
continue;
}
if(mask & (1 << i)) {
cnt1 += a[ i ];
}
}
mp[cnt1]++;
}
for(int mask = 0; mask < (1 << (n / 2) + (n & 1)); mask++) {
int cnt1 = 0;
for(int i = 0; i < (n / 2) + (n & 1); i++) {
if(i + (n / 2) == j) {
continue;
}
if(mask & (1 << i)) {
cnt1 += a[i + (n / 2)];
}
}
if(cnt1 > cnt / 2) {
continue;
}
if(mp[(cnt / 2) - cnt1]) {
fl = true;
break;
}
}
cnt += a[ j ];
if(!fl) {
bl = false;
break;
}
}
if(bl) {
v.pb( x );
}
cnt -= x;
}
cout << v.sz << "\n";
for(auto it : v) {
cout << it << ' ';
}
}
}
signed main() {
// freopen("sum.in", "r", stdin);
// freopen("sum.out", "w", stdout);
boost;
int tt = 1;
// cin >> tt;
for(int i = 1; i <= tt; i++) {
// cout << "Case " << i << ":\n";
solve();
}
}
Compilation message
bootfall.cpp: In function 'void solve()':
bootfall.cpp:131:56: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
131 | for(int mask = 0; mask < (1 << (n / 2) + (n & 1)); mask++) {
| ~~~~~~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
76 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
75 ms |
348 KB |
Output is correct |
9 |
Correct |
13 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
76 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
75 ms |
348 KB |
Output is correct |
9 |
Correct |
13 ms |
348 KB |
Output is correct |
10 |
Execution timed out |
1058 ms |
432 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
76 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
75 ms |
348 KB |
Output is correct |
9 |
Correct |
13 ms |
348 KB |
Output is correct |
10 |
Execution timed out |
1058 ms |
432 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
76 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
75 ms |
348 KB |
Output is correct |
9 |
Correct |
13 ms |
348 KB |
Output is correct |
10 |
Execution timed out |
1058 ms |
432 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
76 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
75 ms |
348 KB |
Output is correct |
9 |
Correct |
13 ms |
348 KB |
Output is correct |
10 |
Execution timed out |
1058 ms |
432 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
76 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
75 ms |
348 KB |
Output is correct |
9 |
Correct |
13 ms |
348 KB |
Output is correct |
10 |
Execution timed out |
1058 ms |
432 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |