//
// ROIGold.cpp
// Main calisma
//
// Created by Rakhman on 05/02/2019.
// Copyright © 2019 Rakhman. All rights reserved.
//
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>
#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define no_answer return cout << 0, 0;
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)
const int MXN = 4e5 + 200;
const long long MNN = 4e2 + 200;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const int OO = 1e9 + 500;
typedef long long llong;
typedef unsigned long long ullong;
using namespace std;
int n, k, a[MXN], cnt;
bitset<126000> pr[510], su[510];
int sum = 0;
vector<int> v;
bool isOk(int k, int pos){
if(pos <= n / 2){
bitset<126000> x = su[pos + 1];
for(int i = 1; i <= pos - 1; i++){
x |= x << a[i];
}
if(x[(sum + k - a[pos]) / 2] == 1){
return 1;
}else{
return 0;
}
}else{
bitset<126000> x = pr[pos - 1];
for(int i = pos + 1; i <= n; i ++){
x |= x << a[i];
}
if(x[(sum + k - a[pos]) / 2] == 1){
return 1;
}else{
return 0;
}
}
}
int main () {
ios;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
sum += a[i];
cnt += a[i] % 2;
}
if(sum % 2 == 1) {
no_answer;
}
if(cnt != 0 && cnt != n){
no_answer;
}
pr[0][0] = 1;
for(int i = 1; i <= n; i++){
pr[i] = pr[i - 1];
pr[i] |= pr[i] << a[i];
}
if(pr[n][sum / 2] == 0){
no_answer;
}
su[n + 1][0] = 1;
for(int i = n; i >= 1; i--){
su[i] = su[i + 1];
su[i] |= su[i] << a[i];
}
for(int i = a[1] % 2; i <= sum; i += 2){
bool ok = 1;
for(int j = 1; j <= n; j++){
if(isOk(i, j) == 0){
ok = 0;
break;
}
}
if(ok == 1) v.pb(i);
}
cout << v.size() << nl;
for(int i = 0; i < v.size(); i++){
cout << v[i] << ' ';
}
}
Compilation message
bootfall.cpp: In function 'int main()':
bootfall.cpp:121:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < v.size(); i++){
~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
3 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
35 ms |
760 KB |
Output is correct |
6 |
Correct |
3 ms |
632 KB |
Output is correct |
7 |
Correct |
3 ms |
632 KB |
Output is correct |
8 |
Correct |
39 ms |
888 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
3 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
35 ms |
760 KB |
Output is correct |
6 |
Correct |
3 ms |
632 KB |
Output is correct |
7 |
Correct |
3 ms |
632 KB |
Output is correct |
8 |
Correct |
39 ms |
888 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
22 ms |
1400 KB |
Output is correct |
11 |
Correct |
153 ms |
1400 KB |
Output is correct |
12 |
Correct |
4 ms |
1400 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
151 ms |
1476 KB |
Output is correct |
15 |
Correct |
115 ms |
1276 KB |
Output is correct |
16 |
Correct |
153 ms |
1420 KB |
Output is correct |
17 |
Correct |
39 ms |
1016 KB |
Output is correct |
18 |
Correct |
94 ms |
1144 KB |
Output is correct |
19 |
Correct |
86 ms |
1372 KB |
Output is correct |
20 |
Correct |
23 ms |
1400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
3 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
35 ms |
760 KB |
Output is correct |
6 |
Correct |
3 ms |
632 KB |
Output is correct |
7 |
Correct |
3 ms |
632 KB |
Output is correct |
8 |
Correct |
39 ms |
888 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
22 ms |
1400 KB |
Output is correct |
11 |
Correct |
153 ms |
1400 KB |
Output is correct |
12 |
Correct |
4 ms |
1400 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
151 ms |
1476 KB |
Output is correct |
15 |
Correct |
115 ms |
1276 KB |
Output is correct |
16 |
Correct |
153 ms |
1420 KB |
Output is correct |
17 |
Correct |
39 ms |
1016 KB |
Output is correct |
18 |
Correct |
94 ms |
1144 KB |
Output is correct |
19 |
Correct |
86 ms |
1372 KB |
Output is correct |
20 |
Correct |
23 ms |
1400 KB |
Output is correct |
21 |
Execution timed out |
1080 ms |
2552 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
3 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
35 ms |
760 KB |
Output is correct |
6 |
Correct |
3 ms |
632 KB |
Output is correct |
7 |
Correct |
3 ms |
632 KB |
Output is correct |
8 |
Correct |
39 ms |
888 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
22 ms |
1400 KB |
Output is correct |
11 |
Correct |
153 ms |
1400 KB |
Output is correct |
12 |
Correct |
4 ms |
1400 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
151 ms |
1476 KB |
Output is correct |
15 |
Correct |
115 ms |
1276 KB |
Output is correct |
16 |
Correct |
153 ms |
1420 KB |
Output is correct |
17 |
Correct |
39 ms |
1016 KB |
Output is correct |
18 |
Correct |
94 ms |
1144 KB |
Output is correct |
19 |
Correct |
86 ms |
1372 KB |
Output is correct |
20 |
Correct |
23 ms |
1400 KB |
Output is correct |
21 |
Execution timed out |
1080 ms |
2552 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
3 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
35 ms |
760 KB |
Output is correct |
6 |
Correct |
3 ms |
632 KB |
Output is correct |
7 |
Correct |
3 ms |
632 KB |
Output is correct |
8 |
Correct |
39 ms |
888 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
22 ms |
1400 KB |
Output is correct |
11 |
Correct |
153 ms |
1400 KB |
Output is correct |
12 |
Correct |
4 ms |
1400 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
151 ms |
1476 KB |
Output is correct |
15 |
Correct |
115 ms |
1276 KB |
Output is correct |
16 |
Correct |
153 ms |
1420 KB |
Output is correct |
17 |
Correct |
39 ms |
1016 KB |
Output is correct |
18 |
Correct |
94 ms |
1144 KB |
Output is correct |
19 |
Correct |
86 ms |
1372 KB |
Output is correct |
20 |
Correct |
23 ms |
1400 KB |
Output is correct |
21 |
Execution timed out |
1080 ms |
2552 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
3 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
35 ms |
760 KB |
Output is correct |
6 |
Correct |
3 ms |
632 KB |
Output is correct |
7 |
Correct |
3 ms |
632 KB |
Output is correct |
8 |
Correct |
39 ms |
888 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
22 ms |
1400 KB |
Output is correct |
11 |
Correct |
153 ms |
1400 KB |
Output is correct |
12 |
Correct |
4 ms |
1400 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
151 ms |
1476 KB |
Output is correct |
15 |
Correct |
115 ms |
1276 KB |
Output is correct |
16 |
Correct |
153 ms |
1420 KB |
Output is correct |
17 |
Correct |
39 ms |
1016 KB |
Output is correct |
18 |
Correct |
94 ms |
1144 KB |
Output is correct |
19 |
Correct |
86 ms |
1372 KB |
Output is correct |
20 |
Correct |
23 ms |
1400 KB |
Output is correct |
21 |
Execution timed out |
1080 ms |
2552 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |