#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]]);
if(ways[j]){
int diff=abs(j-((sum-A[i])-j));
os.insert(diff);
}
}
for(auto x:os){
if(x>=0)cnt[x]++;
}
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 |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 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 |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 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 |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 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 |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 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 |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 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 |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 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 |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 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 |
2392 KB |
Output is correct |
21 |
Correct |
6 ms |
2396 KB |
Output is correct |
22 |
Correct |
7 ms |
2612 KB |
Output is correct |
23 |
Correct |
4 ms |
2396 KB |
Output is correct |
24 |
Correct |
12 ms |
2644 KB |
Output is correct |
25 |
Correct |
18 ms |
2772 KB |
Output is correct |
26 |
Correct |
20 ms |
2652 KB |
Output is correct |
27 |
Correct |
12 ms |
2652 KB |
Output is correct |
28 |
Correct |
14 ms |
2660 KB |
Output is correct |
29 |
Correct |
14 ms |
2684 KB |
Output is correct |
30 |
Correct |
15 ms |
2648 KB |
Output is correct |
31 |
Correct |
19 ms |
2648 KB |
Output is correct |
32 |
Correct |
12 ms |
2652 KB |
Output is correct |
33 |
Correct |
3 ms |
2396 KB |
Output is correct |
34 |
Correct |
3 ms |
2396 KB |
Output is correct |
35 |
Correct |
12 ms |
2652 KB |
Output is correct |
36 |
Correct |
12 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 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 |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 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 |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 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 |
2392 KB |
Output is correct |
21 |
Correct |
6 ms |
2396 KB |
Output is correct |
22 |
Correct |
7 ms |
2612 KB |
Output is correct |
23 |
Correct |
4 ms |
2396 KB |
Output is correct |
24 |
Correct |
12 ms |
2644 KB |
Output is correct |
25 |
Correct |
18 ms |
2772 KB |
Output is correct |
26 |
Correct |
20 ms |
2652 KB |
Output is correct |
27 |
Correct |
12 ms |
2652 KB |
Output is correct |
28 |
Correct |
14 ms |
2660 KB |
Output is correct |
29 |
Correct |
14 ms |
2684 KB |
Output is correct |
30 |
Correct |
15 ms |
2648 KB |
Output is correct |
31 |
Correct |
19 ms |
2648 KB |
Output is correct |
32 |
Correct |
12 ms |
2652 KB |
Output is correct |
33 |
Correct |
3 ms |
2396 KB |
Output is correct |
34 |
Correct |
3 ms |
2396 KB |
Output is correct |
35 |
Correct |
12 ms |
2652 KB |
Output is correct |
36 |
Correct |
12 ms |
2652 KB |
Output is correct |
37 |
Correct |
100 ms |
3024 KB |
Output is correct |
38 |
Correct |
97 ms |
3036 KB |
Output is correct |
39 |
Correct |
29 ms |
2908 KB |
Output is correct |
40 |
Correct |
231 ms |
3356 KB |
Output is correct |
41 |
Correct |
43 ms |
2908 KB |
Output is correct |
42 |
Correct |
199 ms |
3336 KB |
Output is correct |
43 |
Correct |
340 ms |
4020 KB |
Output is correct |
44 |
Correct |
352 ms |
4176 KB |
Output is correct |
45 |
Correct |
361 ms |
4048 KB |
Output is correct |
46 |
Correct |
118 ms |
2996 KB |
Output is correct |
47 |
Correct |
212 ms |
3344 KB |
Output is correct |
48 |
Correct |
341 ms |
4072 KB |
Output is correct |
49 |
Correct |
213 ms |
3540 KB |
Output is correct |
50 |
Correct |
201 ms |
3256 KB |
Output is correct |
51 |
Correct |
4 ms |
2396 KB |
Output is correct |
52 |
Correct |
451 ms |
4268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 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 |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 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 |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 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 |
2392 KB |
Output is correct |
21 |
Correct |
6 ms |
2396 KB |
Output is correct |
22 |
Correct |
7 ms |
2612 KB |
Output is correct |
23 |
Correct |
4 ms |
2396 KB |
Output is correct |
24 |
Correct |
12 ms |
2644 KB |
Output is correct |
25 |
Correct |
18 ms |
2772 KB |
Output is correct |
26 |
Correct |
20 ms |
2652 KB |
Output is correct |
27 |
Correct |
12 ms |
2652 KB |
Output is correct |
28 |
Correct |
14 ms |
2660 KB |
Output is correct |
29 |
Correct |
14 ms |
2684 KB |
Output is correct |
30 |
Correct |
15 ms |
2648 KB |
Output is correct |
31 |
Correct |
19 ms |
2648 KB |
Output is correct |
32 |
Correct |
12 ms |
2652 KB |
Output is correct |
33 |
Correct |
3 ms |
2396 KB |
Output is correct |
34 |
Correct |
3 ms |
2396 KB |
Output is correct |
35 |
Correct |
12 ms |
2652 KB |
Output is correct |
36 |
Correct |
12 ms |
2652 KB |
Output is correct |
37 |
Correct |
100 ms |
3024 KB |
Output is correct |
38 |
Correct |
97 ms |
3036 KB |
Output is correct |
39 |
Correct |
29 ms |
2908 KB |
Output is correct |
40 |
Correct |
231 ms |
3356 KB |
Output is correct |
41 |
Correct |
43 ms |
2908 KB |
Output is correct |
42 |
Correct |
199 ms |
3336 KB |
Output is correct |
43 |
Correct |
340 ms |
4020 KB |
Output is correct |
44 |
Correct |
352 ms |
4176 KB |
Output is correct |
45 |
Correct |
361 ms |
4048 KB |
Output is correct |
46 |
Correct |
118 ms |
2996 KB |
Output is correct |
47 |
Correct |
212 ms |
3344 KB |
Output is correct |
48 |
Correct |
341 ms |
4072 KB |
Output is correct |
49 |
Correct |
213 ms |
3540 KB |
Output is correct |
50 |
Correct |
201 ms |
3256 KB |
Output is correct |
51 |
Correct |
4 ms |
2396 KB |
Output is correct |
52 |
Correct |
451 ms |
4268 KB |
Output is correct |
53 |
Correct |
405 ms |
4024 KB |
Output is correct |
54 |
Correct |
503 ms |
4240 KB |
Output is correct |
55 |
Correct |
958 ms |
5860 KB |
Output is correct |
56 |
Correct |
665 ms |
4052 KB |
Output is correct |
57 |
Execution timed out |
1002 ms |
6584 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 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 |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 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 |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 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 |
2392 KB |
Output is correct |
21 |
Correct |
6 ms |
2396 KB |
Output is correct |
22 |
Correct |
7 ms |
2612 KB |
Output is correct |
23 |
Correct |
4 ms |
2396 KB |
Output is correct |
24 |
Correct |
12 ms |
2644 KB |
Output is correct |
25 |
Correct |
18 ms |
2772 KB |
Output is correct |
26 |
Correct |
20 ms |
2652 KB |
Output is correct |
27 |
Correct |
12 ms |
2652 KB |
Output is correct |
28 |
Correct |
14 ms |
2660 KB |
Output is correct |
29 |
Correct |
14 ms |
2684 KB |
Output is correct |
30 |
Correct |
15 ms |
2648 KB |
Output is correct |
31 |
Correct |
19 ms |
2648 KB |
Output is correct |
32 |
Correct |
12 ms |
2652 KB |
Output is correct |
33 |
Correct |
3 ms |
2396 KB |
Output is correct |
34 |
Correct |
3 ms |
2396 KB |
Output is correct |
35 |
Correct |
12 ms |
2652 KB |
Output is correct |
36 |
Correct |
12 ms |
2652 KB |
Output is correct |
37 |
Correct |
100 ms |
3024 KB |
Output is correct |
38 |
Correct |
97 ms |
3036 KB |
Output is correct |
39 |
Correct |
29 ms |
2908 KB |
Output is correct |
40 |
Correct |
231 ms |
3356 KB |
Output is correct |
41 |
Correct |
43 ms |
2908 KB |
Output is correct |
42 |
Correct |
199 ms |
3336 KB |
Output is correct |
43 |
Correct |
340 ms |
4020 KB |
Output is correct |
44 |
Correct |
352 ms |
4176 KB |
Output is correct |
45 |
Correct |
361 ms |
4048 KB |
Output is correct |
46 |
Correct |
118 ms |
2996 KB |
Output is correct |
47 |
Correct |
212 ms |
3344 KB |
Output is correct |
48 |
Correct |
341 ms |
4072 KB |
Output is correct |
49 |
Correct |
213 ms |
3540 KB |
Output is correct |
50 |
Correct |
201 ms |
3256 KB |
Output is correct |
51 |
Correct |
4 ms |
2396 KB |
Output is correct |
52 |
Correct |
451 ms |
4268 KB |
Output is correct |
53 |
Correct |
405 ms |
4024 KB |
Output is correct |
54 |
Correct |
503 ms |
4240 KB |
Output is correct |
55 |
Correct |
958 ms |
5860 KB |
Output is correct |
56 |
Correct |
665 ms |
4052 KB |
Output is correct |
57 |
Execution timed out |
1002 ms |
6584 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |