/*
_ _ _ _ _ __ _____ _____ _
| | | | _ | | | | | | / | |____ | ___(_)
__ _ _ _| |_| |__ ___ _ __(_) | |__ __ _| | __ _ _ __ __| | __ _ `| | / /___ \ _ __ _
/ _` | | | | __| '_ \ / _ \| '__| | '_ \ / _` | |/ _` | '_ \ / _` |/ _` | | | \ \ \ \ |/ _` |
| (_| | |_| | |_| | | | (_) | | _ | |_) | (_| | | (_| | | | | (_| | (_| | _| |_.___/ /\__/ / | (_| |
\__,_|\__,_|\__|_| |_|\___/|_| (_) |_.__/ \__,_|_|\__,_|_| |_|\__,_|\__,_| \___/\____/\____/|_|\__, |
| |
|_|
__ _ __ _ _ __ ___ __ ___ _________ ___
/ _` |/ _` | | '_ ` _ \ / _` \ \ / /_ / _ \/ __|
| (_| | (_| | | | | | | | (_| |\ V / / / __/\__ \
\__, |\__, | |_| |_| |_|\__,_| \_/ /___\___||___/
| | | |
|_| |_|
* */
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
template<class T>
istream& operator>>(istream &in, vector<T> &v){
for(auto &to: v) in >> to;
return in;
}
template<class T>
ostream& operator<<(ostream &out, const vector<T> &v){
for(auto &to: v) out << v << ' ';
return out;
}
template<class U, class V>
istream& operator>>(istream &in, pair<U, V> &v){
in >> v.first >> v.second;
return in;
}
template<class U, class V>
ostream& operator<<(ostream &out, const pair<U, V> &v){
out << v.first << ' ' << v.second;
return out;
}
#ifdef DEBUG
#define dbg(x) cout << "debug:" << __LINE__ << ' ' << #x << "=" << x
#else
#define dbg(x) 42
#endif
int solve(){
int n;
cin >> n;
vector<int> v(n);
cin >> v;
int sm = 0;
for(int i = 0; i < n; i++)
sm += v[i];
vector<bitset<72902> > dpp(n + 1);
vector<bitset<72902> > dps(n + 1);
dpp[0][0] = 1;
dps[n][0] = 1;
for(int i = 1; i <= n; i++){
dpp[i] = dpp[i - 1];
dpp[i] |= (dpp[i - 1] << v[i - 1]);
}
for(int i = n - 1; i >= 0; i--){
dps[i] = dps[i + 1];
dps[i] |= (dps[i + 1] << v[i]);
}
if(!dpp[n][sm / 2]){
cout << 0;
return 0;
}
set<int> possible;
for(int j = 1; j < 72902; j++) {
possible.insert(j);
}
for(int i = 0; i < n; i++){
bitset<72902> crr;
for(int j = 0; j < 72902; j++){
if(dpp[i][j])
crr |= (dps[i + 1] << j);
}
vector<int> bad;
for(auto to: possible){
int full = (sm - v[i] + to);
if(full % 2) bad.push_back(to);
else if(!(crr[full / 2] && crr[full / 2 - to])){
bad.push_back(to);
}
}
for(auto to: bad) possible.erase(to);
}
cout << possible.size() << endl;
for(auto to: possible){
cout << to << ' ';
}
return 0;
}
signed main() {
#ifdef DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while(t --> 0){
assert(solve() == 0);
cout << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
4964 KB |
Output is correct |
2 |
Correct |
26 ms |
5092 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
22 ms |
4964 KB |
Output is correct |
5 |
Correct |
32 ms |
5220 KB |
Output is correct |
6 |
Correct |
26 ms |
5092 KB |
Output is correct |
7 |
Correct |
24 ms |
5092 KB |
Output is correct |
8 |
Correct |
29 ms |
5220 KB |
Output is correct |
9 |
Correct |
27 ms |
5092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
4964 KB |
Output is correct |
2 |
Correct |
26 ms |
5092 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
22 ms |
4964 KB |
Output is correct |
5 |
Correct |
32 ms |
5220 KB |
Output is correct |
6 |
Correct |
26 ms |
5092 KB |
Output is correct |
7 |
Correct |
24 ms |
5092 KB |
Output is correct |
8 |
Correct |
29 ms |
5220 KB |
Output is correct |
9 |
Correct |
27 ms |
5092 KB |
Output is correct |
10 |
Correct |
27 ms |
5504 KB |
Output is correct |
11 |
Correct |
46 ms |
5484 KB |
Output is correct |
12 |
Correct |
33 ms |
5484 KB |
Output is correct |
13 |
Correct |
35 ms |
5484 KB |
Output is correct |
14 |
Correct |
37 ms |
5484 KB |
Output is correct |
15 |
Correct |
43 ms |
5484 KB |
Output is correct |
16 |
Correct |
36 ms |
5484 KB |
Output is correct |
17 |
Correct |
28 ms |
5228 KB |
Output is correct |
18 |
Correct |
34 ms |
5356 KB |
Output is correct |
19 |
Correct |
41 ms |
5484 KB |
Output is correct |
20 |
Correct |
28 ms |
5484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
4964 KB |
Output is correct |
2 |
Correct |
26 ms |
5092 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
22 ms |
4964 KB |
Output is correct |
5 |
Correct |
32 ms |
5220 KB |
Output is correct |
6 |
Correct |
26 ms |
5092 KB |
Output is correct |
7 |
Correct |
24 ms |
5092 KB |
Output is correct |
8 |
Correct |
29 ms |
5220 KB |
Output is correct |
9 |
Correct |
27 ms |
5092 KB |
Output is correct |
10 |
Correct |
27 ms |
5504 KB |
Output is correct |
11 |
Correct |
46 ms |
5484 KB |
Output is correct |
12 |
Correct |
33 ms |
5484 KB |
Output is correct |
13 |
Correct |
35 ms |
5484 KB |
Output is correct |
14 |
Correct |
37 ms |
5484 KB |
Output is correct |
15 |
Correct |
43 ms |
5484 KB |
Output is correct |
16 |
Correct |
36 ms |
5484 KB |
Output is correct |
17 |
Correct |
28 ms |
5228 KB |
Output is correct |
18 |
Correct |
34 ms |
5356 KB |
Output is correct |
19 |
Correct |
41 ms |
5484 KB |
Output is correct |
20 |
Correct |
28 ms |
5484 KB |
Output is correct |
21 |
Correct |
277 ms |
6124 KB |
Output is correct |
22 |
Correct |
395 ms |
6248 KB |
Output is correct |
23 |
Correct |
197 ms |
5868 KB |
Output is correct |
24 |
Correct |
563 ms |
6632 KB |
Output is correct |
25 |
Correct |
664 ms |
6632 KB |
Output is correct |
26 |
Correct |
743 ms |
6760 KB |
Output is correct |
27 |
Correct |
498 ms |
6760 KB |
Output is correct |
28 |
Correct |
394 ms |
6760 KB |
Output is correct |
29 |
Correct |
429 ms |
6760 KB |
Output is correct |
30 |
Correct |
694 ms |
6760 KB |
Output is correct |
31 |
Correct |
909 ms |
6760 KB |
Output is correct |
32 |
Correct |
613 ms |
6760 KB |
Output is correct |
33 |
Correct |
47 ms |
6760 KB |
Output is correct |
34 |
Correct |
48 ms |
6760 KB |
Output is correct |
35 |
Correct |
357 ms |
6760 KB |
Output is correct |
36 |
Correct |
594 ms |
6760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
4964 KB |
Output is correct |
2 |
Correct |
26 ms |
5092 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
22 ms |
4964 KB |
Output is correct |
5 |
Correct |
32 ms |
5220 KB |
Output is correct |
6 |
Correct |
26 ms |
5092 KB |
Output is correct |
7 |
Correct |
24 ms |
5092 KB |
Output is correct |
8 |
Correct |
29 ms |
5220 KB |
Output is correct |
9 |
Correct |
27 ms |
5092 KB |
Output is correct |
10 |
Correct |
27 ms |
5504 KB |
Output is correct |
11 |
Correct |
46 ms |
5484 KB |
Output is correct |
12 |
Correct |
33 ms |
5484 KB |
Output is correct |
13 |
Correct |
35 ms |
5484 KB |
Output is correct |
14 |
Correct |
37 ms |
5484 KB |
Output is correct |
15 |
Correct |
43 ms |
5484 KB |
Output is correct |
16 |
Correct |
36 ms |
5484 KB |
Output is correct |
17 |
Correct |
28 ms |
5228 KB |
Output is correct |
18 |
Correct |
34 ms |
5356 KB |
Output is correct |
19 |
Correct |
41 ms |
5484 KB |
Output is correct |
20 |
Correct |
28 ms |
5484 KB |
Output is correct |
21 |
Correct |
277 ms |
6124 KB |
Output is correct |
22 |
Correct |
395 ms |
6248 KB |
Output is correct |
23 |
Correct |
197 ms |
5868 KB |
Output is correct |
24 |
Correct |
563 ms |
6632 KB |
Output is correct |
25 |
Correct |
664 ms |
6632 KB |
Output is correct |
26 |
Correct |
743 ms |
6760 KB |
Output is correct |
27 |
Correct |
498 ms |
6760 KB |
Output is correct |
28 |
Correct |
394 ms |
6760 KB |
Output is correct |
29 |
Correct |
429 ms |
6760 KB |
Output is correct |
30 |
Correct |
694 ms |
6760 KB |
Output is correct |
31 |
Correct |
909 ms |
6760 KB |
Output is correct |
32 |
Correct |
613 ms |
6760 KB |
Output is correct |
33 |
Correct |
47 ms |
6760 KB |
Output is correct |
34 |
Correct |
48 ms |
6760 KB |
Output is correct |
35 |
Correct |
357 ms |
6760 KB |
Output is correct |
36 |
Correct |
594 ms |
6760 KB |
Output is correct |
37 |
Execution timed out |
1079 ms |
8044 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
4964 KB |
Output is correct |
2 |
Correct |
26 ms |
5092 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
22 ms |
4964 KB |
Output is correct |
5 |
Correct |
32 ms |
5220 KB |
Output is correct |
6 |
Correct |
26 ms |
5092 KB |
Output is correct |
7 |
Correct |
24 ms |
5092 KB |
Output is correct |
8 |
Correct |
29 ms |
5220 KB |
Output is correct |
9 |
Correct |
27 ms |
5092 KB |
Output is correct |
10 |
Correct |
27 ms |
5504 KB |
Output is correct |
11 |
Correct |
46 ms |
5484 KB |
Output is correct |
12 |
Correct |
33 ms |
5484 KB |
Output is correct |
13 |
Correct |
35 ms |
5484 KB |
Output is correct |
14 |
Correct |
37 ms |
5484 KB |
Output is correct |
15 |
Correct |
43 ms |
5484 KB |
Output is correct |
16 |
Correct |
36 ms |
5484 KB |
Output is correct |
17 |
Correct |
28 ms |
5228 KB |
Output is correct |
18 |
Correct |
34 ms |
5356 KB |
Output is correct |
19 |
Correct |
41 ms |
5484 KB |
Output is correct |
20 |
Correct |
28 ms |
5484 KB |
Output is correct |
21 |
Correct |
277 ms |
6124 KB |
Output is correct |
22 |
Correct |
395 ms |
6248 KB |
Output is correct |
23 |
Correct |
197 ms |
5868 KB |
Output is correct |
24 |
Correct |
563 ms |
6632 KB |
Output is correct |
25 |
Correct |
664 ms |
6632 KB |
Output is correct |
26 |
Correct |
743 ms |
6760 KB |
Output is correct |
27 |
Correct |
498 ms |
6760 KB |
Output is correct |
28 |
Correct |
394 ms |
6760 KB |
Output is correct |
29 |
Correct |
429 ms |
6760 KB |
Output is correct |
30 |
Correct |
694 ms |
6760 KB |
Output is correct |
31 |
Correct |
909 ms |
6760 KB |
Output is correct |
32 |
Correct |
613 ms |
6760 KB |
Output is correct |
33 |
Correct |
47 ms |
6760 KB |
Output is correct |
34 |
Correct |
48 ms |
6760 KB |
Output is correct |
35 |
Correct |
357 ms |
6760 KB |
Output is correct |
36 |
Correct |
594 ms |
6760 KB |
Output is correct |
37 |
Execution timed out |
1079 ms |
8044 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
4964 KB |
Output is correct |
2 |
Correct |
26 ms |
5092 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
22 ms |
4964 KB |
Output is correct |
5 |
Correct |
32 ms |
5220 KB |
Output is correct |
6 |
Correct |
26 ms |
5092 KB |
Output is correct |
7 |
Correct |
24 ms |
5092 KB |
Output is correct |
8 |
Correct |
29 ms |
5220 KB |
Output is correct |
9 |
Correct |
27 ms |
5092 KB |
Output is correct |
10 |
Correct |
27 ms |
5504 KB |
Output is correct |
11 |
Correct |
46 ms |
5484 KB |
Output is correct |
12 |
Correct |
33 ms |
5484 KB |
Output is correct |
13 |
Correct |
35 ms |
5484 KB |
Output is correct |
14 |
Correct |
37 ms |
5484 KB |
Output is correct |
15 |
Correct |
43 ms |
5484 KB |
Output is correct |
16 |
Correct |
36 ms |
5484 KB |
Output is correct |
17 |
Correct |
28 ms |
5228 KB |
Output is correct |
18 |
Correct |
34 ms |
5356 KB |
Output is correct |
19 |
Correct |
41 ms |
5484 KB |
Output is correct |
20 |
Correct |
28 ms |
5484 KB |
Output is correct |
21 |
Correct |
277 ms |
6124 KB |
Output is correct |
22 |
Correct |
395 ms |
6248 KB |
Output is correct |
23 |
Correct |
197 ms |
5868 KB |
Output is correct |
24 |
Correct |
563 ms |
6632 KB |
Output is correct |
25 |
Correct |
664 ms |
6632 KB |
Output is correct |
26 |
Correct |
743 ms |
6760 KB |
Output is correct |
27 |
Correct |
498 ms |
6760 KB |
Output is correct |
28 |
Correct |
394 ms |
6760 KB |
Output is correct |
29 |
Correct |
429 ms |
6760 KB |
Output is correct |
30 |
Correct |
694 ms |
6760 KB |
Output is correct |
31 |
Correct |
909 ms |
6760 KB |
Output is correct |
32 |
Correct |
613 ms |
6760 KB |
Output is correct |
33 |
Correct |
47 ms |
6760 KB |
Output is correct |
34 |
Correct |
48 ms |
6760 KB |
Output is correct |
35 |
Correct |
357 ms |
6760 KB |
Output is correct |
36 |
Correct |
594 ms |
6760 KB |
Output is correct |
37 |
Execution timed out |
1079 ms |
8044 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |