#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 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+a[i]; j<=poc; j++){
dp[ofs + j] = sub(dp[ofs + j], dp[ofs + j - a[i]]);
}
for(int j=1; j<=poc; j++) moze[j] += (dp[ofs + j - a[i]/2] > 0);
for(int j=poc; j>=-poc+a[i]; j--){
dp[ofs + j] = add(dp[ofs + j], dp[ofs + j - a[i]]);
}
}
vector <int> vec;
for(int i=1; i<=N*N; 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 |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 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 |
1 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 |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 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 |
1 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 |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
1 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 |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 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 |
1 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 |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
1 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 |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
4 ms |
332 KB |
Output is correct |
22 |
Correct |
4 ms |
380 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
6 ms |
380 KB |
Output is correct |
25 |
Correct |
8 ms |
460 KB |
Output is correct |
26 |
Correct |
10 ms |
460 KB |
Output is correct |
27 |
Correct |
8 ms |
460 KB |
Output is correct |
28 |
Correct |
8 ms |
444 KB |
Output is correct |
29 |
Correct |
9 ms |
440 KB |
Output is correct |
30 |
Correct |
6 ms |
388 KB |
Output is correct |
31 |
Correct |
9 ms |
412 KB |
Output is correct |
32 |
Correct |
7 ms |
408 KB |
Output is correct |
33 |
Correct |
9 ms |
332 KB |
Output is correct |
34 |
Correct |
9 ms |
460 KB |
Output is correct |
35 |
Correct |
9 ms |
440 KB |
Output is correct |
36 |
Correct |
5 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 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 |
1 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 |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
1 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 |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
4 ms |
332 KB |
Output is correct |
22 |
Correct |
4 ms |
380 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
6 ms |
380 KB |
Output is correct |
25 |
Correct |
8 ms |
460 KB |
Output is correct |
26 |
Correct |
10 ms |
460 KB |
Output is correct |
27 |
Correct |
8 ms |
460 KB |
Output is correct |
28 |
Correct |
8 ms |
444 KB |
Output is correct |
29 |
Correct |
9 ms |
440 KB |
Output is correct |
30 |
Correct |
6 ms |
388 KB |
Output is correct |
31 |
Correct |
9 ms |
412 KB |
Output is correct |
32 |
Correct |
7 ms |
408 KB |
Output is correct |
33 |
Correct |
9 ms |
332 KB |
Output is correct |
34 |
Correct |
9 ms |
460 KB |
Output is correct |
35 |
Correct |
9 ms |
440 KB |
Output is correct |
36 |
Correct |
5 ms |
332 KB |
Output is correct |
37 |
Correct |
31 ms |
588 KB |
Output is correct |
38 |
Correct |
38 ms |
596 KB |
Output is correct |
39 |
Correct |
118 ms |
1032 KB |
Output is correct |
40 |
Correct |
67 ms |
836 KB |
Output is correct |
41 |
Correct |
154 ms |
1220 KB |
Output is correct |
42 |
Correct |
59 ms |
788 KB |
Output is correct |
43 |
Correct |
103 ms |
1252 KB |
Output is correct |
44 |
Correct |
110 ms |
1340 KB |
Output is correct |
45 |
Correct |
111 ms |
1268 KB |
Output is correct |
46 |
Correct |
65 ms |
672 KB |
Output is correct |
47 |
Correct |
64 ms |
836 KB |
Output is correct |
48 |
Correct |
121 ms |
1276 KB |
Output is correct |
49 |
Correct |
120 ms |
1056 KB |
Output is correct |
50 |
Correct |
64 ms |
836 KB |
Output is correct |
51 |
Correct |
18 ms |
568 KB |
Output is correct |
52 |
Correct |
159 ms |
1504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 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 |
1 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 |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
1 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 |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
4 ms |
332 KB |
Output is correct |
22 |
Correct |
4 ms |
380 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
6 ms |
380 KB |
Output is correct |
25 |
Correct |
8 ms |
460 KB |
Output is correct |
26 |
Correct |
10 ms |
460 KB |
Output is correct |
27 |
Correct |
8 ms |
460 KB |
Output is correct |
28 |
Correct |
8 ms |
444 KB |
Output is correct |
29 |
Correct |
9 ms |
440 KB |
Output is correct |
30 |
Correct |
6 ms |
388 KB |
Output is correct |
31 |
Correct |
9 ms |
412 KB |
Output is correct |
32 |
Correct |
7 ms |
408 KB |
Output is correct |
33 |
Correct |
9 ms |
332 KB |
Output is correct |
34 |
Correct |
9 ms |
460 KB |
Output is correct |
35 |
Correct |
9 ms |
440 KB |
Output is correct |
36 |
Correct |
5 ms |
332 KB |
Output is correct |
37 |
Correct |
31 ms |
588 KB |
Output is correct |
38 |
Correct |
38 ms |
596 KB |
Output is correct |
39 |
Correct |
118 ms |
1032 KB |
Output is correct |
40 |
Correct |
67 ms |
836 KB |
Output is correct |
41 |
Correct |
154 ms |
1220 KB |
Output is correct |
42 |
Correct |
59 ms |
788 KB |
Output is correct |
43 |
Correct |
103 ms |
1252 KB |
Output is correct |
44 |
Correct |
110 ms |
1340 KB |
Output is correct |
45 |
Correct |
111 ms |
1268 KB |
Output is correct |
46 |
Correct |
65 ms |
672 KB |
Output is correct |
47 |
Correct |
64 ms |
836 KB |
Output is correct |
48 |
Correct |
121 ms |
1276 KB |
Output is correct |
49 |
Correct |
120 ms |
1056 KB |
Output is correct |
50 |
Correct |
64 ms |
836 KB |
Output is correct |
51 |
Correct |
18 ms |
568 KB |
Output is correct |
52 |
Correct |
159 ms |
1504 KB |
Output is correct |
53 |
Correct |
105 ms |
1184 KB |
Output is correct |
54 |
Correct |
147 ms |
1336 KB |
Output is correct |
55 |
Correct |
305 ms |
2124 KB |
Output is correct |
56 |
Correct |
137 ms |
1348 KB |
Output is correct |
57 |
Correct |
326 ms |
2380 KB |
Output is correct |
58 |
Correct |
205 ms |
1348 KB |
Output is correct |
59 |
Correct |
210 ms |
1584 KB |
Output is correct |
60 |
Correct |
50 ms |
784 KB |
Output is correct |
61 |
Correct |
229 ms |
1756 KB |
Output is correct |
62 |
Correct |
243 ms |
1992 KB |
Output is correct |
63 |
Correct |
256 ms |
2032 KB |
Output is correct |
64 |
Correct |
279 ms |
2028 KB |
Output is correct |
65 |
Correct |
120 ms |
836 KB |
Output is correct |
66 |
Correct |
129 ms |
968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 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 |
1 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 |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
1 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 |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
4 ms |
332 KB |
Output is correct |
22 |
Correct |
4 ms |
380 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
6 ms |
380 KB |
Output is correct |
25 |
Correct |
8 ms |
460 KB |
Output is correct |
26 |
Correct |
10 ms |
460 KB |
Output is correct |
27 |
Correct |
8 ms |
460 KB |
Output is correct |
28 |
Correct |
8 ms |
444 KB |
Output is correct |
29 |
Correct |
9 ms |
440 KB |
Output is correct |
30 |
Correct |
6 ms |
388 KB |
Output is correct |
31 |
Correct |
9 ms |
412 KB |
Output is correct |
32 |
Correct |
7 ms |
408 KB |
Output is correct |
33 |
Correct |
9 ms |
332 KB |
Output is correct |
34 |
Correct |
9 ms |
460 KB |
Output is correct |
35 |
Correct |
9 ms |
440 KB |
Output is correct |
36 |
Correct |
5 ms |
332 KB |
Output is correct |
37 |
Correct |
31 ms |
588 KB |
Output is correct |
38 |
Correct |
38 ms |
596 KB |
Output is correct |
39 |
Correct |
118 ms |
1032 KB |
Output is correct |
40 |
Correct |
67 ms |
836 KB |
Output is correct |
41 |
Correct |
154 ms |
1220 KB |
Output is correct |
42 |
Correct |
59 ms |
788 KB |
Output is correct |
43 |
Correct |
103 ms |
1252 KB |
Output is correct |
44 |
Correct |
110 ms |
1340 KB |
Output is correct |
45 |
Correct |
111 ms |
1268 KB |
Output is correct |
46 |
Correct |
65 ms |
672 KB |
Output is correct |
47 |
Correct |
64 ms |
836 KB |
Output is correct |
48 |
Correct |
121 ms |
1276 KB |
Output is correct |
49 |
Correct |
120 ms |
1056 KB |
Output is correct |
50 |
Correct |
64 ms |
836 KB |
Output is correct |
51 |
Correct |
18 ms |
568 KB |
Output is correct |
52 |
Correct |
159 ms |
1504 KB |
Output is correct |
53 |
Correct |
105 ms |
1184 KB |
Output is correct |
54 |
Correct |
147 ms |
1336 KB |
Output is correct |
55 |
Correct |
305 ms |
2124 KB |
Output is correct |
56 |
Correct |
137 ms |
1348 KB |
Output is correct |
57 |
Correct |
326 ms |
2380 KB |
Output is correct |
58 |
Correct |
205 ms |
1348 KB |
Output is correct |
59 |
Correct |
210 ms |
1584 KB |
Output is correct |
60 |
Correct |
50 ms |
784 KB |
Output is correct |
61 |
Correct |
229 ms |
1756 KB |
Output is correct |
62 |
Correct |
243 ms |
1992 KB |
Output is correct |
63 |
Correct |
256 ms |
2032 KB |
Output is correct |
64 |
Correct |
279 ms |
2028 KB |
Output is correct |
65 |
Correct |
120 ms |
836 KB |
Output is correct |
66 |
Correct |
129 ms |
968 KB |
Output is correct |
67 |
Correct |
247 ms |
1716 KB |
Output is correct |
68 |
Correct |
142 ms |
1268 KB |
Output is correct |
69 |
Correct |
817 ms |
4012 KB |
Output is correct |
70 |
Correct |
498 ms |
2592 KB |
Output is correct |
71 |
Correct |
482 ms |
2504 KB |
Output is correct |
72 |
Correct |
472 ms |
1780 KB |
Output is correct |
73 |
Correct |
525 ms |
1732 KB |
Output is correct |
74 |
Correct |
847 ms |
4088 KB |
Output is correct |
75 |
Correct |
669 ms |
3268 KB |
Output is correct |
76 |
Execution timed out |
1041 ms |
4332 KB |
Time limit exceeded |
77 |
Halted |
0 ms |
0 KB |
- |