#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 500;
const int ofs = N*N;
const int MOD = 1000000007;
int add(int a, int b){ a += b; if(a >= MOD) a -= MOD; return a; }
int sub(int a, int b){ return add(a, MOD - b); }
int moze[N*N+5];
int dp[2*N*N+5];
int ddp[2*N*N+5];
int a[N+5];
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int n;
cin >> n;
int poc = 0;
for(int i=1; i<=n; i++){
cin >> a[i];
poc += a[i];
a[i] *= 2;
}
dp[ofs - poc] = 1;
for(int i=1; i<=n; i++){
for(int j=poc; j>=-poc+a[i]; j--){
dp[ofs + j] = add(dp[ofs + j], dp[ofs + j - a[i]]);
}
}
if(dp[ofs] == 0){
cout << "0\n";
return 0;
}
for(int i=1; i<=n; i++){
for(int j=-poc; j<=poc; j++){
ddp[ofs + j] = dp[ofs + j];
if(ofs + j - a[i] >= 0) ddp[ofs + j] = sub(ddp[ofs + j], ddp[ofs + j - a[i]]);
}
for(int j=1; j<=poc; j++) moze[j] += (ddp[ofs + j - a[i]/2] > 0);
}
vector <int> vec;
for(int i=1; i<=poc; i++) if(moze[i] == n) vec.push_back(i);
cout << vec.size() << "\n";
for(auto c : vec) cout << c << " ";
cout << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
4 ms |
460 KB |
Output is correct |
25 |
Correct |
7 ms |
460 KB |
Output is correct |
26 |
Correct |
7 ms |
520 KB |
Output is correct |
27 |
Correct |
6 ms |
460 KB |
Output is correct |
28 |
Correct |
7 ms |
460 KB |
Output is correct |
29 |
Correct |
7 ms |
460 KB |
Output is correct |
30 |
Correct |
4 ms |
332 KB |
Output is correct |
31 |
Correct |
6 ms |
484 KB |
Output is correct |
32 |
Correct |
4 ms |
420 KB |
Output is correct |
33 |
Correct |
7 ms |
460 KB |
Output is correct |
34 |
Correct |
9 ms |
528 KB |
Output is correct |
35 |
Correct |
7 ms |
460 KB |
Output is correct |
36 |
Correct |
5 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
4 ms |
460 KB |
Output is correct |
25 |
Correct |
7 ms |
460 KB |
Output is correct |
26 |
Correct |
7 ms |
520 KB |
Output is correct |
27 |
Correct |
6 ms |
460 KB |
Output is correct |
28 |
Correct |
7 ms |
460 KB |
Output is correct |
29 |
Correct |
7 ms |
460 KB |
Output is correct |
30 |
Correct |
4 ms |
332 KB |
Output is correct |
31 |
Correct |
6 ms |
484 KB |
Output is correct |
32 |
Correct |
4 ms |
420 KB |
Output is correct |
33 |
Correct |
7 ms |
460 KB |
Output is correct |
34 |
Correct |
9 ms |
528 KB |
Output is correct |
35 |
Correct |
7 ms |
460 KB |
Output is correct |
36 |
Correct |
5 ms |
460 KB |
Output is correct |
37 |
Correct |
26 ms |
824 KB |
Output is correct |
38 |
Correct |
27 ms |
836 KB |
Output is correct |
39 |
Correct |
100 ms |
1424 KB |
Output is correct |
40 |
Correct |
59 ms |
1100 KB |
Output is correct |
41 |
Correct |
127 ms |
1640 KB |
Output is correct |
42 |
Correct |
50 ms |
1028 KB |
Output is correct |
43 |
Correct |
93 ms |
1732 KB |
Output is correct |
44 |
Correct |
107 ms |
1780 KB |
Output is correct |
45 |
Correct |
95 ms |
1776 KB |
Output is correct |
46 |
Correct |
54 ms |
844 KB |
Output is correct |
47 |
Correct |
53 ms |
1096 KB |
Output is correct |
48 |
Correct |
104 ms |
1780 KB |
Output is correct |
49 |
Correct |
103 ms |
1532 KB |
Output is correct |
50 |
Correct |
53 ms |
1076 KB |
Output is correct |
51 |
Correct |
20 ms |
568 KB |
Output is correct |
52 |
Correct |
124 ms |
2068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
4 ms |
460 KB |
Output is correct |
25 |
Correct |
7 ms |
460 KB |
Output is correct |
26 |
Correct |
7 ms |
520 KB |
Output is correct |
27 |
Correct |
6 ms |
460 KB |
Output is correct |
28 |
Correct |
7 ms |
460 KB |
Output is correct |
29 |
Correct |
7 ms |
460 KB |
Output is correct |
30 |
Correct |
4 ms |
332 KB |
Output is correct |
31 |
Correct |
6 ms |
484 KB |
Output is correct |
32 |
Correct |
4 ms |
420 KB |
Output is correct |
33 |
Correct |
7 ms |
460 KB |
Output is correct |
34 |
Correct |
9 ms |
528 KB |
Output is correct |
35 |
Correct |
7 ms |
460 KB |
Output is correct |
36 |
Correct |
5 ms |
460 KB |
Output is correct |
37 |
Correct |
26 ms |
824 KB |
Output is correct |
38 |
Correct |
27 ms |
836 KB |
Output is correct |
39 |
Correct |
100 ms |
1424 KB |
Output is correct |
40 |
Correct |
59 ms |
1100 KB |
Output is correct |
41 |
Correct |
127 ms |
1640 KB |
Output is correct |
42 |
Correct |
50 ms |
1028 KB |
Output is correct |
43 |
Correct |
93 ms |
1732 KB |
Output is correct |
44 |
Correct |
107 ms |
1780 KB |
Output is correct |
45 |
Correct |
95 ms |
1776 KB |
Output is correct |
46 |
Correct |
54 ms |
844 KB |
Output is correct |
47 |
Correct |
53 ms |
1096 KB |
Output is correct |
48 |
Correct |
104 ms |
1780 KB |
Output is correct |
49 |
Correct |
103 ms |
1532 KB |
Output is correct |
50 |
Correct |
53 ms |
1076 KB |
Output is correct |
51 |
Correct |
20 ms |
568 KB |
Output is correct |
52 |
Correct |
124 ms |
2068 KB |
Output is correct |
53 |
Correct |
96 ms |
1460 KB |
Output is correct |
54 |
Correct |
128 ms |
1784 KB |
Output is correct |
55 |
Correct |
261 ms |
3016 KB |
Output is correct |
56 |
Correct |
111 ms |
1788 KB |
Output is correct |
57 |
Correct |
275 ms |
3140 KB |
Output is correct |
58 |
Correct |
139 ms |
1896 KB |
Output is correct |
59 |
Correct |
175 ms |
2248 KB |
Output is correct |
60 |
Correct |
49 ms |
784 KB |
Output is correct |
61 |
Correct |
196 ms |
2524 KB |
Output is correct |
62 |
Correct |
199 ms |
2696 KB |
Output is correct |
63 |
Correct |
231 ms |
2920 KB |
Output is correct |
64 |
Correct |
212 ms |
2832 KB |
Output is correct |
65 |
Correct |
102 ms |
1248 KB |
Output is correct |
66 |
Correct |
106 ms |
1352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
4 ms |
460 KB |
Output is correct |
25 |
Correct |
7 ms |
460 KB |
Output is correct |
26 |
Correct |
7 ms |
520 KB |
Output is correct |
27 |
Correct |
6 ms |
460 KB |
Output is correct |
28 |
Correct |
7 ms |
460 KB |
Output is correct |
29 |
Correct |
7 ms |
460 KB |
Output is correct |
30 |
Correct |
4 ms |
332 KB |
Output is correct |
31 |
Correct |
6 ms |
484 KB |
Output is correct |
32 |
Correct |
4 ms |
420 KB |
Output is correct |
33 |
Correct |
7 ms |
460 KB |
Output is correct |
34 |
Correct |
9 ms |
528 KB |
Output is correct |
35 |
Correct |
7 ms |
460 KB |
Output is correct |
36 |
Correct |
5 ms |
460 KB |
Output is correct |
37 |
Correct |
26 ms |
824 KB |
Output is correct |
38 |
Correct |
27 ms |
836 KB |
Output is correct |
39 |
Correct |
100 ms |
1424 KB |
Output is correct |
40 |
Correct |
59 ms |
1100 KB |
Output is correct |
41 |
Correct |
127 ms |
1640 KB |
Output is correct |
42 |
Correct |
50 ms |
1028 KB |
Output is correct |
43 |
Correct |
93 ms |
1732 KB |
Output is correct |
44 |
Correct |
107 ms |
1780 KB |
Output is correct |
45 |
Correct |
95 ms |
1776 KB |
Output is correct |
46 |
Correct |
54 ms |
844 KB |
Output is correct |
47 |
Correct |
53 ms |
1096 KB |
Output is correct |
48 |
Correct |
104 ms |
1780 KB |
Output is correct |
49 |
Correct |
103 ms |
1532 KB |
Output is correct |
50 |
Correct |
53 ms |
1076 KB |
Output is correct |
51 |
Correct |
20 ms |
568 KB |
Output is correct |
52 |
Correct |
124 ms |
2068 KB |
Output is correct |
53 |
Correct |
96 ms |
1460 KB |
Output is correct |
54 |
Correct |
128 ms |
1784 KB |
Output is correct |
55 |
Correct |
261 ms |
3016 KB |
Output is correct |
56 |
Correct |
111 ms |
1788 KB |
Output is correct |
57 |
Correct |
275 ms |
3140 KB |
Output is correct |
58 |
Correct |
139 ms |
1896 KB |
Output is correct |
59 |
Correct |
175 ms |
2248 KB |
Output is correct |
60 |
Correct |
49 ms |
784 KB |
Output is correct |
61 |
Correct |
196 ms |
2524 KB |
Output is correct |
62 |
Correct |
199 ms |
2696 KB |
Output is correct |
63 |
Correct |
231 ms |
2920 KB |
Output is correct |
64 |
Correct |
212 ms |
2832 KB |
Output is correct |
65 |
Correct |
102 ms |
1248 KB |
Output is correct |
66 |
Correct |
106 ms |
1352 KB |
Output is correct |
67 |
Correct |
215 ms |
2396 KB |
Output is correct |
68 |
Correct |
137 ms |
1228 KB |
Output is correct |
69 |
Correct |
727 ms |
5604 KB |
Output is correct |
70 |
Correct |
414 ms |
3596 KB |
Output is correct |
71 |
Correct |
430 ms |
3516 KB |
Output is correct |
72 |
Correct |
441 ms |
2760 KB |
Output is correct |
73 |
Correct |
400 ms |
2752 KB |
Output is correct |
74 |
Correct |
736 ms |
5840 KB |
Output is correct |
75 |
Correct |
650 ms |
4744 KB |
Output is correct |
76 |
Correct |
804 ms |
6248 KB |
Output is correct |
77 |
Correct |
778 ms |
6232 KB |
Output is correct |