#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD1 = (int)1e9 + 7;
int n;
int A[505];
unsigned long long ways[505*505]; // natural overflow
int cnt[505*500];
int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n;
int sum=0;
for(int i=1;i<=n;i++){
cin>>A[i];
sum+=A[i];
}
ways[0]=1;
ways[0]=1;
ways[0]=1;
for(int i=1;i<=n;i++){
for(int j=sum;j>=0;j--){
if(j-A[i]>=0)ways[j]=(ways[j]+ways[j-A[i]]);
}
}
unordered_set<int>os;
if(sum % 2 == 1){
return cout << 0,0;
}
if(ways[sum/2] == 0){
return cout << 0,0;
}
for(int i=1;i<=n;i++){ // remove this
unordered_set<int>os;
for(int j=0;j<=sum;j++){
if(j-A[i]>=0)ways[j]=(ways[j]-ways[j-A[i]]);
}
for(int j=0;j<=(sum-A[i])/2;j++){
if(ways[j]){
int diff=abs(j-((sum-A[i])-j));
if(diff>=0)cnt[diff]++;
}
}
for(int j=sum;j>=0;j--){
if(j-A[i]>=0)ways[j]=(ways[j]+ways[j-A[i]]);
}
}
vector<int>out;
for(int j=1;j<=sum;j++){
if(cnt[j] == n){
out.push_back(j);
}
}
cout<<out.size()<<"\n";
for(auto x:out)cout<<x<<" ";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2648 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2648 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2648 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2392 KB |
Output is correct |
24 |
Correct |
2 ms |
2396 KB |
Output is correct |
25 |
Correct |
4 ms |
2652 KB |
Output is correct |
26 |
Correct |
3 ms |
2652 KB |
Output is correct |
27 |
Correct |
3 ms |
2392 KB |
Output is correct |
28 |
Correct |
3 ms |
2396 KB |
Output is correct |
29 |
Correct |
3 ms |
2396 KB |
Output is correct |
30 |
Correct |
2 ms |
2396 KB |
Output is correct |
31 |
Correct |
3 ms |
2652 KB |
Output is correct |
32 |
Correct |
2 ms |
2396 KB |
Output is correct |
33 |
Correct |
3 ms |
2396 KB |
Output is correct |
34 |
Correct |
3 ms |
2396 KB |
Output is correct |
35 |
Correct |
3 ms |
2396 KB |
Output is correct |
36 |
Correct |
2 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2648 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2392 KB |
Output is correct |
24 |
Correct |
2 ms |
2396 KB |
Output is correct |
25 |
Correct |
4 ms |
2652 KB |
Output is correct |
26 |
Correct |
3 ms |
2652 KB |
Output is correct |
27 |
Correct |
3 ms |
2392 KB |
Output is correct |
28 |
Correct |
3 ms |
2396 KB |
Output is correct |
29 |
Correct |
3 ms |
2396 KB |
Output is correct |
30 |
Correct |
2 ms |
2396 KB |
Output is correct |
31 |
Correct |
3 ms |
2652 KB |
Output is correct |
32 |
Correct |
2 ms |
2396 KB |
Output is correct |
33 |
Correct |
3 ms |
2396 KB |
Output is correct |
34 |
Correct |
3 ms |
2396 KB |
Output is correct |
35 |
Correct |
3 ms |
2396 KB |
Output is correct |
36 |
Correct |
2 ms |
2396 KB |
Output is correct |
37 |
Correct |
12 ms |
2908 KB |
Output is correct |
38 |
Correct |
11 ms |
2908 KB |
Output is correct |
39 |
Correct |
35 ms |
2908 KB |
Output is correct |
40 |
Correct |
20 ms |
2908 KB |
Output is correct |
41 |
Correct |
43 ms |
2972 KB |
Output is correct |
42 |
Correct |
19 ms |
2908 KB |
Output is correct |
43 |
Correct |
31 ms |
3296 KB |
Output is correct |
44 |
Correct |
33 ms |
3296 KB |
Output is correct |
45 |
Correct |
40 ms |
3540 KB |
Output is correct |
46 |
Correct |
24 ms |
2652 KB |
Output is correct |
47 |
Correct |
21 ms |
2908 KB |
Output is correct |
48 |
Correct |
35 ms |
3284 KB |
Output is correct |
49 |
Correct |
45 ms |
2916 KB |
Output is correct |
50 |
Correct |
19 ms |
2904 KB |
Output is correct |
51 |
Correct |
5 ms |
2396 KB |
Output is correct |
52 |
Correct |
44 ms |
3444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2648 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2392 KB |
Output is correct |
24 |
Correct |
2 ms |
2396 KB |
Output is correct |
25 |
Correct |
4 ms |
2652 KB |
Output is correct |
26 |
Correct |
3 ms |
2652 KB |
Output is correct |
27 |
Correct |
3 ms |
2392 KB |
Output is correct |
28 |
Correct |
3 ms |
2396 KB |
Output is correct |
29 |
Correct |
3 ms |
2396 KB |
Output is correct |
30 |
Correct |
2 ms |
2396 KB |
Output is correct |
31 |
Correct |
3 ms |
2652 KB |
Output is correct |
32 |
Correct |
2 ms |
2396 KB |
Output is correct |
33 |
Correct |
3 ms |
2396 KB |
Output is correct |
34 |
Correct |
3 ms |
2396 KB |
Output is correct |
35 |
Correct |
3 ms |
2396 KB |
Output is correct |
36 |
Correct |
2 ms |
2396 KB |
Output is correct |
37 |
Correct |
12 ms |
2908 KB |
Output is correct |
38 |
Correct |
11 ms |
2908 KB |
Output is correct |
39 |
Correct |
35 ms |
2908 KB |
Output is correct |
40 |
Correct |
20 ms |
2908 KB |
Output is correct |
41 |
Correct |
43 ms |
2972 KB |
Output is correct |
42 |
Correct |
19 ms |
2908 KB |
Output is correct |
43 |
Correct |
31 ms |
3296 KB |
Output is correct |
44 |
Correct |
33 ms |
3296 KB |
Output is correct |
45 |
Correct |
40 ms |
3540 KB |
Output is correct |
46 |
Correct |
24 ms |
2652 KB |
Output is correct |
47 |
Correct |
21 ms |
2908 KB |
Output is correct |
48 |
Correct |
35 ms |
3284 KB |
Output is correct |
49 |
Correct |
45 ms |
2916 KB |
Output is correct |
50 |
Correct |
19 ms |
2904 KB |
Output is correct |
51 |
Correct |
5 ms |
2396 KB |
Output is correct |
52 |
Correct |
44 ms |
3444 KB |
Output is correct |
53 |
Correct |
32 ms |
3152 KB |
Output is correct |
54 |
Correct |
45 ms |
3284 KB |
Output is correct |
55 |
Correct |
96 ms |
4048 KB |
Output is correct |
56 |
Correct |
39 ms |
3292 KB |
Output is correct |
57 |
Correct |
93 ms |
4052 KB |
Output is correct |
58 |
Correct |
49 ms |
3296 KB |
Output is correct |
59 |
Correct |
64 ms |
3656 KB |
Output is correct |
60 |
Correct |
12 ms |
2652 KB |
Output is correct |
61 |
Correct |
69 ms |
3604 KB |
Output is correct |
62 |
Correct |
78 ms |
3808 KB |
Output is correct |
63 |
Correct |
84 ms |
3952 KB |
Output is correct |
64 |
Correct |
80 ms |
3796 KB |
Output is correct |
65 |
Correct |
37 ms |
2652 KB |
Output is correct |
66 |
Correct |
37 ms |
2908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2648 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2392 KB |
Output is correct |
24 |
Correct |
2 ms |
2396 KB |
Output is correct |
25 |
Correct |
4 ms |
2652 KB |
Output is correct |
26 |
Correct |
3 ms |
2652 KB |
Output is correct |
27 |
Correct |
3 ms |
2392 KB |
Output is correct |
28 |
Correct |
3 ms |
2396 KB |
Output is correct |
29 |
Correct |
3 ms |
2396 KB |
Output is correct |
30 |
Correct |
2 ms |
2396 KB |
Output is correct |
31 |
Correct |
3 ms |
2652 KB |
Output is correct |
32 |
Correct |
2 ms |
2396 KB |
Output is correct |
33 |
Correct |
3 ms |
2396 KB |
Output is correct |
34 |
Correct |
3 ms |
2396 KB |
Output is correct |
35 |
Correct |
3 ms |
2396 KB |
Output is correct |
36 |
Correct |
2 ms |
2396 KB |
Output is correct |
37 |
Correct |
12 ms |
2908 KB |
Output is correct |
38 |
Correct |
11 ms |
2908 KB |
Output is correct |
39 |
Correct |
35 ms |
2908 KB |
Output is correct |
40 |
Correct |
20 ms |
2908 KB |
Output is correct |
41 |
Correct |
43 ms |
2972 KB |
Output is correct |
42 |
Correct |
19 ms |
2908 KB |
Output is correct |
43 |
Correct |
31 ms |
3296 KB |
Output is correct |
44 |
Correct |
33 ms |
3296 KB |
Output is correct |
45 |
Correct |
40 ms |
3540 KB |
Output is correct |
46 |
Correct |
24 ms |
2652 KB |
Output is correct |
47 |
Correct |
21 ms |
2908 KB |
Output is correct |
48 |
Correct |
35 ms |
3284 KB |
Output is correct |
49 |
Correct |
45 ms |
2916 KB |
Output is correct |
50 |
Correct |
19 ms |
2904 KB |
Output is correct |
51 |
Correct |
5 ms |
2396 KB |
Output is correct |
52 |
Correct |
44 ms |
3444 KB |
Output is correct |
53 |
Correct |
32 ms |
3152 KB |
Output is correct |
54 |
Correct |
45 ms |
3284 KB |
Output is correct |
55 |
Correct |
96 ms |
4048 KB |
Output is correct |
56 |
Correct |
39 ms |
3292 KB |
Output is correct |
57 |
Correct |
93 ms |
4052 KB |
Output is correct |
58 |
Correct |
49 ms |
3296 KB |
Output is correct |
59 |
Correct |
64 ms |
3656 KB |
Output is correct |
60 |
Correct |
12 ms |
2652 KB |
Output is correct |
61 |
Correct |
69 ms |
3604 KB |
Output is correct |
62 |
Correct |
78 ms |
3808 KB |
Output is correct |
63 |
Correct |
84 ms |
3952 KB |
Output is correct |
64 |
Correct |
80 ms |
3796 KB |
Output is correct |
65 |
Correct |
37 ms |
2652 KB |
Output is correct |
66 |
Correct |
37 ms |
2908 KB |
Output is correct |
67 |
Correct |
73 ms |
3688 KB |
Output is correct |
68 |
Correct |
34 ms |
3160 KB |
Output is correct |
69 |
Correct |
238 ms |
5560 KB |
Output is correct |
70 |
Correct |
162 ms |
4316 KB |
Output is correct |
71 |
Correct |
140 ms |
4308 KB |
Output is correct |
72 |
Correct |
137 ms |
3400 KB |
Output is correct |
73 |
Correct |
136 ms |
3224 KB |
Output is correct |
74 |
Correct |
248 ms |
5652 KB |
Output is correct |
75 |
Correct |
217 ms |
5068 KB |
Output is correct |
76 |
Correct |
286 ms |
5736 KB |
Output is correct |
77 |
Correct |
273 ms |
5944 KB |
Output is correct |