//#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define all(a) a.begin(),a.end()
#define ull unsigned long long
#define endl '\n'
#define y1 yaumru
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define iter vector<int>::iterator
using namespace std;
using namespace __gnu_pbds;
template<class T>
using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class T>
using ordered_multiset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rnd1(chrono::steady_clock::now().time_since_epoch().count());
//find_by_order
//order_of_key
const int N=500+1;
const int inf=1e9+1e9;
const int mod=1e9+7;
const ld eps=1e-9;
const int M=200000+1;
bitset<M>dp[N];
bitset<M>pref[N];
int a[N];
bool used[N];
main ()
{
ios;
int n;
cin>>n;
for (int i=1;i<=n;++i){
cin>>a[i];
}
int sum=0;
bool c1=false;
bool c2=false;
for (int i=1;i<=n;++i){
sum+=a[i];
if (a[i]%2==1){
c1=true;
}
else {
c2=true;
}
}
if (c1 && c2){
cout<<0<<endl;
exit(0);
}
if (sum%2==1){
cout<<0<<endl;
exit(0);
}
pref[0][0]=1;
for (int i=1;i<=n;++i){
pref[i]=(pref[i-1]|(pref[i-1]<<a[i]));
}
for (int i=0;i<=n;++i){
if (i==0){
dp[i][0]=1;
for (int j=1;j<=n;++j){
if (j==i)continue;
bitset<M>f=(dp[i]<<a[j]);
dp[i]=(dp[i]|f);
}
if (dp[0][sum/2]==0){
cout<<0<<endl;
exit(0);
}
}
else {
if (!used[a[i]]){
used[a[i]]=true;
dp[a[i]]=pref[i-1];
for (int j=i+1;j<=n;++j){
if (j==i)continue;
bitset<M>f=(dp[a[i]]<<a[j]);
dp[a[i]]=(dp[a[i]]|f);
}
}
}
}
vector<int>ans;
for (int i=1;i<=M;++i){
bool cc=true;
for (int j=1;j<=n;++j){
if ((sum-a[j]+i)%2==1){
cc=false;
break;
}
if ((sum-a[j]+i)%2==0){
if (dp[a[j]][(sum-a[j]+i)/2]==0){
cc=false;
break;
}
}
}
if (cc)ans.pb(i);
}
cout<<(int)ans.size()<<endl;
for (int i=0;i<ans.size();++i){
cout<<ans[i]<<' ';
}
}
Compilation message
bootfall.cpp:43:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main ()
^
bootfall.cpp: In function 'int main()':
bootfall.cpp:118:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0;i<ans.size();++i){
~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
632 KB |
Output is correct |
2 |
Correct |
3 ms |
760 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
3 ms |
676 KB |
Output is correct |
5 |
Correct |
4 ms |
1144 KB |
Output is correct |
6 |
Correct |
4 ms |
888 KB |
Output is correct |
7 |
Correct |
3 ms |
760 KB |
Output is correct |
8 |
Correct |
4 ms |
1144 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
632 KB |
Output is correct |
2 |
Correct |
3 ms |
760 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
3 ms |
676 KB |
Output is correct |
5 |
Correct |
4 ms |
1144 KB |
Output is correct |
6 |
Correct |
4 ms |
888 KB |
Output is correct |
7 |
Correct |
3 ms |
760 KB |
Output is correct |
8 |
Correct |
4 ms |
1144 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
1272 KB |
Output is correct |
11 |
Correct |
8 ms |
1540 KB |
Output is correct |
12 |
Correct |
8 ms |
1532 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
7 ms |
1404 KB |
Output is correct |
15 |
Correct |
7 ms |
1400 KB |
Output is correct |
16 |
Correct |
7 ms |
1532 KB |
Output is correct |
17 |
Correct |
6 ms |
1144 KB |
Output is correct |
18 |
Correct |
6 ms |
1272 KB |
Output is correct |
19 |
Correct |
7 ms |
1400 KB |
Output is correct |
20 |
Correct |
4 ms |
1272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
632 KB |
Output is correct |
2 |
Correct |
3 ms |
760 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
3 ms |
676 KB |
Output is correct |
5 |
Correct |
4 ms |
1144 KB |
Output is correct |
6 |
Correct |
4 ms |
888 KB |
Output is correct |
7 |
Correct |
3 ms |
760 KB |
Output is correct |
8 |
Correct |
4 ms |
1144 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
1272 KB |
Output is correct |
11 |
Correct |
8 ms |
1540 KB |
Output is correct |
12 |
Correct |
8 ms |
1532 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
7 ms |
1404 KB |
Output is correct |
15 |
Correct |
7 ms |
1400 KB |
Output is correct |
16 |
Correct |
7 ms |
1532 KB |
Output is correct |
17 |
Correct |
6 ms |
1144 KB |
Output is correct |
18 |
Correct |
6 ms |
1272 KB |
Output is correct |
19 |
Correct |
7 ms |
1400 KB |
Output is correct |
20 |
Correct |
4 ms |
1272 KB |
Output is correct |
21 |
Correct |
27 ms |
3192 KB |
Output is correct |
22 |
Correct |
34 ms |
3440 KB |
Output is correct |
23 |
Correct |
18 ms |
2468 KB |
Output is correct |
24 |
Correct |
47 ms |
4088 KB |
Output is correct |
25 |
Correct |
16 ms |
3056 KB |
Output is correct |
26 |
Correct |
17 ms |
3192 KB |
Output is correct |
27 |
Correct |
16 ms |
3192 KB |
Output is correct |
28 |
Correct |
10 ms |
3064 KB |
Output is correct |
29 |
Correct |
12 ms |
3068 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
37 ms |
3704 KB |
Output is correct |
32 |
Correct |
50 ms |
4216 KB |
Output is correct |
33 |
Correct |
10 ms |
3064 KB |
Output is correct |
34 |
Correct |
9 ms |
2936 KB |
Output is correct |
35 |
Correct |
11 ms |
3096 KB |
Output is correct |
36 |
Correct |
55 ms |
4472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
632 KB |
Output is correct |
2 |
Correct |
3 ms |
760 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
3 ms |
676 KB |
Output is correct |
5 |
Correct |
4 ms |
1144 KB |
Output is correct |
6 |
Correct |
4 ms |
888 KB |
Output is correct |
7 |
Correct |
3 ms |
760 KB |
Output is correct |
8 |
Correct |
4 ms |
1144 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
1272 KB |
Output is correct |
11 |
Correct |
8 ms |
1540 KB |
Output is correct |
12 |
Correct |
8 ms |
1532 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
7 ms |
1404 KB |
Output is correct |
15 |
Correct |
7 ms |
1400 KB |
Output is correct |
16 |
Correct |
7 ms |
1532 KB |
Output is correct |
17 |
Correct |
6 ms |
1144 KB |
Output is correct |
18 |
Correct |
6 ms |
1272 KB |
Output is correct |
19 |
Correct |
7 ms |
1400 KB |
Output is correct |
20 |
Correct |
4 ms |
1272 KB |
Output is correct |
21 |
Correct |
27 ms |
3192 KB |
Output is correct |
22 |
Correct |
34 ms |
3440 KB |
Output is correct |
23 |
Correct |
18 ms |
2468 KB |
Output is correct |
24 |
Correct |
47 ms |
4088 KB |
Output is correct |
25 |
Correct |
16 ms |
3056 KB |
Output is correct |
26 |
Correct |
17 ms |
3192 KB |
Output is correct |
27 |
Correct |
16 ms |
3192 KB |
Output is correct |
28 |
Correct |
10 ms |
3064 KB |
Output is correct |
29 |
Correct |
12 ms |
3068 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
37 ms |
3704 KB |
Output is correct |
32 |
Correct |
50 ms |
4216 KB |
Output is correct |
33 |
Correct |
10 ms |
3064 KB |
Output is correct |
34 |
Correct |
9 ms |
2936 KB |
Output is correct |
35 |
Correct |
11 ms |
3096 KB |
Output is correct |
36 |
Correct |
55 ms |
4472 KB |
Output is correct |
37 |
Correct |
125 ms |
6900 KB |
Output is correct |
38 |
Correct |
132 ms |
6996 KB |
Output is correct |
39 |
Correct |
18 ms |
6520 KB |
Output is correct |
40 |
Correct |
354 ms |
11416 KB |
Output is correct |
41 |
Correct |
19 ms |
7156 KB |
Output is correct |
42 |
Correct |
273 ms |
10016 KB |
Output is correct |
43 |
Correct |
112 ms |
7608 KB |
Output is correct |
44 |
Correct |
118 ms |
7764 KB |
Output is correct |
45 |
Correct |
119 ms |
7804 KB |
Output is correct |
46 |
Correct |
320 ms |
11028 KB |
Output is correct |
47 |
Correct |
282 ms |
9900 KB |
Output is correct |
48 |
Correct |
49 ms |
7032 KB |
Output is correct |
49 |
Correct |
29 ms |
6776 KB |
Output is correct |
50 |
Correct |
309 ms |
10468 KB |
Output is correct |
51 |
Correct |
2 ms |
376 KB |
Output is correct |
52 |
Correct |
85 ms |
7824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
632 KB |
Output is correct |
2 |
Correct |
3 ms |
760 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
3 ms |
676 KB |
Output is correct |
5 |
Correct |
4 ms |
1144 KB |
Output is correct |
6 |
Correct |
4 ms |
888 KB |
Output is correct |
7 |
Correct |
3 ms |
760 KB |
Output is correct |
8 |
Correct |
4 ms |
1144 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
1272 KB |
Output is correct |
11 |
Correct |
8 ms |
1540 KB |
Output is correct |
12 |
Correct |
8 ms |
1532 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
7 ms |
1404 KB |
Output is correct |
15 |
Correct |
7 ms |
1400 KB |
Output is correct |
16 |
Correct |
7 ms |
1532 KB |
Output is correct |
17 |
Correct |
6 ms |
1144 KB |
Output is correct |
18 |
Correct |
6 ms |
1272 KB |
Output is correct |
19 |
Correct |
7 ms |
1400 KB |
Output is correct |
20 |
Correct |
4 ms |
1272 KB |
Output is correct |
21 |
Correct |
27 ms |
3192 KB |
Output is correct |
22 |
Correct |
34 ms |
3440 KB |
Output is correct |
23 |
Correct |
18 ms |
2468 KB |
Output is correct |
24 |
Correct |
47 ms |
4088 KB |
Output is correct |
25 |
Correct |
16 ms |
3056 KB |
Output is correct |
26 |
Correct |
17 ms |
3192 KB |
Output is correct |
27 |
Correct |
16 ms |
3192 KB |
Output is correct |
28 |
Correct |
10 ms |
3064 KB |
Output is correct |
29 |
Correct |
12 ms |
3068 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
37 ms |
3704 KB |
Output is correct |
32 |
Correct |
50 ms |
4216 KB |
Output is correct |
33 |
Correct |
10 ms |
3064 KB |
Output is correct |
34 |
Correct |
9 ms |
2936 KB |
Output is correct |
35 |
Correct |
11 ms |
3096 KB |
Output is correct |
36 |
Correct |
55 ms |
4472 KB |
Output is correct |
37 |
Correct |
125 ms |
6900 KB |
Output is correct |
38 |
Correct |
132 ms |
6996 KB |
Output is correct |
39 |
Correct |
18 ms |
6520 KB |
Output is correct |
40 |
Correct |
354 ms |
11416 KB |
Output is correct |
41 |
Correct |
19 ms |
7156 KB |
Output is correct |
42 |
Correct |
273 ms |
10016 KB |
Output is correct |
43 |
Correct |
112 ms |
7608 KB |
Output is correct |
44 |
Correct |
118 ms |
7764 KB |
Output is correct |
45 |
Correct |
119 ms |
7804 KB |
Output is correct |
46 |
Correct |
320 ms |
11028 KB |
Output is correct |
47 |
Correct |
282 ms |
9900 KB |
Output is correct |
48 |
Correct |
49 ms |
7032 KB |
Output is correct |
49 |
Correct |
29 ms |
6776 KB |
Output is correct |
50 |
Correct |
309 ms |
10468 KB |
Output is correct |
51 |
Correct |
2 ms |
376 KB |
Output is correct |
52 |
Correct |
85 ms |
7824 KB |
Output is correct |
53 |
Correct |
361 ms |
11676 KB |
Output is correct |
54 |
Correct |
472 ms |
13068 KB |
Output is correct |
55 |
Correct |
137 ms |
10120 KB |
Output is correct |
56 |
Correct |
418 ms |
12252 KB |
Output is correct |
57 |
Correct |
157 ms |
10240 KB |
Output is correct |
58 |
Correct |
609 ms |
14508 KB |
Output is correct |
59 |
Correct |
424 ms |
12356 KB |
Output is correct |
60 |
Correct |
2 ms |
376 KB |
Output is correct |
61 |
Correct |
422 ms |
12560 KB |
Output is correct |
62 |
Correct |
266 ms |
10420 KB |
Output is correct |
63 |
Correct |
180 ms |
9860 KB |
Output is correct |
64 |
Correct |
175 ms |
9584 KB |
Output is correct |
65 |
Correct |
55 ms |
8568 KB |
Output is correct |
66 |
Correct |
156 ms |
9212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
632 KB |
Output is correct |
2 |
Correct |
3 ms |
760 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
3 ms |
676 KB |
Output is correct |
5 |
Correct |
4 ms |
1144 KB |
Output is correct |
6 |
Correct |
4 ms |
888 KB |
Output is correct |
7 |
Correct |
3 ms |
760 KB |
Output is correct |
8 |
Correct |
4 ms |
1144 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
1272 KB |
Output is correct |
11 |
Correct |
8 ms |
1540 KB |
Output is correct |
12 |
Correct |
8 ms |
1532 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
7 ms |
1404 KB |
Output is correct |
15 |
Correct |
7 ms |
1400 KB |
Output is correct |
16 |
Correct |
7 ms |
1532 KB |
Output is correct |
17 |
Correct |
6 ms |
1144 KB |
Output is correct |
18 |
Correct |
6 ms |
1272 KB |
Output is correct |
19 |
Correct |
7 ms |
1400 KB |
Output is correct |
20 |
Correct |
4 ms |
1272 KB |
Output is correct |
21 |
Correct |
27 ms |
3192 KB |
Output is correct |
22 |
Correct |
34 ms |
3440 KB |
Output is correct |
23 |
Correct |
18 ms |
2468 KB |
Output is correct |
24 |
Correct |
47 ms |
4088 KB |
Output is correct |
25 |
Correct |
16 ms |
3056 KB |
Output is correct |
26 |
Correct |
17 ms |
3192 KB |
Output is correct |
27 |
Correct |
16 ms |
3192 KB |
Output is correct |
28 |
Correct |
10 ms |
3064 KB |
Output is correct |
29 |
Correct |
12 ms |
3068 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
37 ms |
3704 KB |
Output is correct |
32 |
Correct |
50 ms |
4216 KB |
Output is correct |
33 |
Correct |
10 ms |
3064 KB |
Output is correct |
34 |
Correct |
9 ms |
2936 KB |
Output is correct |
35 |
Correct |
11 ms |
3096 KB |
Output is correct |
36 |
Correct |
55 ms |
4472 KB |
Output is correct |
37 |
Correct |
125 ms |
6900 KB |
Output is correct |
38 |
Correct |
132 ms |
6996 KB |
Output is correct |
39 |
Correct |
18 ms |
6520 KB |
Output is correct |
40 |
Correct |
354 ms |
11416 KB |
Output is correct |
41 |
Correct |
19 ms |
7156 KB |
Output is correct |
42 |
Correct |
273 ms |
10016 KB |
Output is correct |
43 |
Correct |
112 ms |
7608 KB |
Output is correct |
44 |
Correct |
118 ms |
7764 KB |
Output is correct |
45 |
Correct |
119 ms |
7804 KB |
Output is correct |
46 |
Correct |
320 ms |
11028 KB |
Output is correct |
47 |
Correct |
282 ms |
9900 KB |
Output is correct |
48 |
Correct |
49 ms |
7032 KB |
Output is correct |
49 |
Correct |
29 ms |
6776 KB |
Output is correct |
50 |
Correct |
309 ms |
10468 KB |
Output is correct |
51 |
Correct |
2 ms |
376 KB |
Output is correct |
52 |
Correct |
85 ms |
7824 KB |
Output is correct |
53 |
Correct |
361 ms |
11676 KB |
Output is correct |
54 |
Correct |
472 ms |
13068 KB |
Output is correct |
55 |
Correct |
137 ms |
10120 KB |
Output is correct |
56 |
Correct |
418 ms |
12252 KB |
Output is correct |
57 |
Correct |
157 ms |
10240 KB |
Output is correct |
58 |
Correct |
609 ms |
14508 KB |
Output is correct |
59 |
Correct |
424 ms |
12356 KB |
Output is correct |
60 |
Correct |
2 ms |
376 KB |
Output is correct |
61 |
Correct |
422 ms |
12560 KB |
Output is correct |
62 |
Correct |
266 ms |
10420 KB |
Output is correct |
63 |
Correct |
180 ms |
9860 KB |
Output is correct |
64 |
Correct |
175 ms |
9584 KB |
Output is correct |
65 |
Correct |
55 ms |
8568 KB |
Output is correct |
66 |
Correct |
156 ms |
9212 KB |
Output is correct |
67 |
Correct |
645 ms |
16584 KB |
Output is correct |
68 |
Correct |
26 ms |
12664 KB |
Output is correct |
69 |
Incorrect |
362 ms |
14820 KB |
Output isn't correct |
70 |
Halted |
0 ms |
0 KB |
- |