#include <bits/stdc++.h>
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define p_b push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define sset ordered_set
#define sqr(x) (x)*(x)
#define pw(x) (1ll << x)
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MAXN = 1123456;
const ll N = 500;
const ll M = N * N;
const ll mod = 1e9 + 7;
const ll inf = 3e18;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());
template <typename T> void vout(T s){cout << s << endl;exit(0);}
int dp[MAXN], kol[MAXN];
bool f[MAXN];
int main(){
ios_base :: sync_with_stdio(0);
cin.tie(0);
dp[0] = 1;
int n;
cin >> n;
vector <int> a(n + 1);
for(int i = 1; i <= n; i++)cin >> a[i];
int sc = 0;
vector <int> pref(n + 1);
for(int i = 1; i <= n; i++){
for(int j = pref[i - 1] + a[i]; j >= a[i]; j--){
dp[j] += dp[j - a[i]];
if(dp[j] >= mod)dp[j] -= mod;
}
pref[i] = pref[i - 1] + a[i];
}
sc = pref[n];
if(sc % 2)vout(0);
if(!dp[sc / 2])vout(0);
int S;
vector <int> ans, can;
for(int i = 1; i <= pref[n]; i++)ans.p_b(i);
for(int i = 1; i <= n; i++){
if(f[a[i]])continue;
f[a[i]] = 1;
for(int j = a[i]; j <= pref[n]; j++){
dp[j] -= dp[j - a[i]];
if(dp[j] < 0)dp[j] += mod;
}
for(auto j : ans){
S = sc - a[i] + j;
if(S % 2 == 0 && dp[S / 2])can.p_b(j);
}
ans.clear();
ans = can;
can.clear();
for(int j = pref[n]; j >= a[i]; j--){
dp[j] += dp[j - a[i]];
if(dp[j] >= mod)dp[j] -= mod;
}
}
cout << ans.size() << "\n";
for(auto i : ans)cout << i << " ";
cout << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
380 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
380 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
3 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
380 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
4 ms |
476 KB |
Output is correct |
25 |
Correct |
3 ms |
504 KB |
Output is correct |
26 |
Correct |
3 ms |
504 KB |
Output is correct |
27 |
Correct |
3 ms |
504 KB |
Output is correct |
28 |
Correct |
3 ms |
504 KB |
Output is correct |
29 |
Correct |
3 ms |
504 KB |
Output is correct |
30 |
Correct |
4 ms |
376 KB |
Output is correct |
31 |
Correct |
4 ms |
504 KB |
Output is correct |
32 |
Correct |
4 ms |
376 KB |
Output is correct |
33 |
Correct |
3 ms |
504 KB |
Output is correct |
34 |
Correct |
3 ms |
504 KB |
Output is correct |
35 |
Correct |
3 ms |
508 KB |
Output is correct |
36 |
Correct |
4 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
380 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
3 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
380 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
4 ms |
476 KB |
Output is correct |
25 |
Correct |
3 ms |
504 KB |
Output is correct |
26 |
Correct |
3 ms |
504 KB |
Output is correct |
27 |
Correct |
3 ms |
504 KB |
Output is correct |
28 |
Correct |
3 ms |
504 KB |
Output is correct |
29 |
Correct |
3 ms |
504 KB |
Output is correct |
30 |
Correct |
4 ms |
376 KB |
Output is correct |
31 |
Correct |
4 ms |
504 KB |
Output is correct |
32 |
Correct |
4 ms |
376 KB |
Output is correct |
33 |
Correct |
3 ms |
504 KB |
Output is correct |
34 |
Correct |
3 ms |
504 KB |
Output is correct |
35 |
Correct |
3 ms |
508 KB |
Output is correct |
36 |
Correct |
4 ms |
504 KB |
Output is correct |
37 |
Correct |
11 ms |
760 KB |
Output is correct |
38 |
Correct |
12 ms |
632 KB |
Output is correct |
39 |
Correct |
17 ms |
1016 KB |
Output is correct |
40 |
Correct |
34 ms |
924 KB |
Output is correct |
41 |
Correct |
21 ms |
1400 KB |
Output is correct |
42 |
Correct |
27 ms |
760 KB |
Output is correct |
43 |
Correct |
24 ms |
1144 KB |
Output is correct |
44 |
Correct |
24 ms |
1184 KB |
Output is correct |
45 |
Correct |
25 ms |
1144 KB |
Output is correct |
46 |
Correct |
26 ms |
760 KB |
Output is correct |
47 |
Correct |
29 ms |
888 KB |
Output is correct |
48 |
Correct |
20 ms |
1272 KB |
Output is correct |
49 |
Correct |
18 ms |
1016 KB |
Output is correct |
50 |
Correct |
31 ms |
760 KB |
Output is correct |
51 |
Correct |
9 ms |
508 KB |
Output is correct |
52 |
Correct |
26 ms |
1272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
380 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
3 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
380 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
4 ms |
476 KB |
Output is correct |
25 |
Correct |
3 ms |
504 KB |
Output is correct |
26 |
Correct |
3 ms |
504 KB |
Output is correct |
27 |
Correct |
3 ms |
504 KB |
Output is correct |
28 |
Correct |
3 ms |
504 KB |
Output is correct |
29 |
Correct |
3 ms |
504 KB |
Output is correct |
30 |
Correct |
4 ms |
376 KB |
Output is correct |
31 |
Correct |
4 ms |
504 KB |
Output is correct |
32 |
Correct |
4 ms |
376 KB |
Output is correct |
33 |
Correct |
3 ms |
504 KB |
Output is correct |
34 |
Correct |
3 ms |
504 KB |
Output is correct |
35 |
Correct |
3 ms |
508 KB |
Output is correct |
36 |
Correct |
4 ms |
504 KB |
Output is correct |
37 |
Correct |
11 ms |
760 KB |
Output is correct |
38 |
Correct |
12 ms |
632 KB |
Output is correct |
39 |
Correct |
17 ms |
1016 KB |
Output is correct |
40 |
Correct |
34 ms |
924 KB |
Output is correct |
41 |
Correct |
21 ms |
1400 KB |
Output is correct |
42 |
Correct |
27 ms |
760 KB |
Output is correct |
43 |
Correct |
24 ms |
1144 KB |
Output is correct |
44 |
Correct |
24 ms |
1184 KB |
Output is correct |
45 |
Correct |
25 ms |
1144 KB |
Output is correct |
46 |
Correct |
26 ms |
760 KB |
Output is correct |
47 |
Correct |
29 ms |
888 KB |
Output is correct |
48 |
Correct |
20 ms |
1272 KB |
Output is correct |
49 |
Correct |
18 ms |
1016 KB |
Output is correct |
50 |
Correct |
31 ms |
760 KB |
Output is correct |
51 |
Correct |
9 ms |
508 KB |
Output is correct |
52 |
Correct |
26 ms |
1272 KB |
Output is correct |
53 |
Correct |
43 ms |
1016 KB |
Output is correct |
54 |
Correct |
55 ms |
1144 KB |
Output is correct |
55 |
Correct |
49 ms |
2008 KB |
Output is correct |
56 |
Correct |
56 ms |
1272 KB |
Output is correct |
57 |
Correct |
54 ms |
2092 KB |
Output is correct |
58 |
Correct |
78 ms |
1376 KB |
Output is correct |
59 |
Correct |
68 ms |
1652 KB |
Output is correct |
60 |
Correct |
21 ms |
632 KB |
Output is correct |
61 |
Correct |
76 ms |
1780 KB |
Output is correct |
62 |
Correct |
59 ms |
1780 KB |
Output is correct |
63 |
Correct |
52 ms |
1908 KB |
Output is correct |
64 |
Correct |
64 ms |
1908 KB |
Output is correct |
65 |
Correct |
19 ms |
888 KB |
Output is correct |
66 |
Correct |
26 ms |
1016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
380 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
3 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
380 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
4 ms |
476 KB |
Output is correct |
25 |
Correct |
3 ms |
504 KB |
Output is correct |
26 |
Correct |
3 ms |
504 KB |
Output is correct |
27 |
Correct |
3 ms |
504 KB |
Output is correct |
28 |
Correct |
3 ms |
504 KB |
Output is correct |
29 |
Correct |
3 ms |
504 KB |
Output is correct |
30 |
Correct |
4 ms |
376 KB |
Output is correct |
31 |
Correct |
4 ms |
504 KB |
Output is correct |
32 |
Correct |
4 ms |
376 KB |
Output is correct |
33 |
Correct |
3 ms |
504 KB |
Output is correct |
34 |
Correct |
3 ms |
504 KB |
Output is correct |
35 |
Correct |
3 ms |
508 KB |
Output is correct |
36 |
Correct |
4 ms |
504 KB |
Output is correct |
37 |
Correct |
11 ms |
760 KB |
Output is correct |
38 |
Correct |
12 ms |
632 KB |
Output is correct |
39 |
Correct |
17 ms |
1016 KB |
Output is correct |
40 |
Correct |
34 ms |
924 KB |
Output is correct |
41 |
Correct |
21 ms |
1400 KB |
Output is correct |
42 |
Correct |
27 ms |
760 KB |
Output is correct |
43 |
Correct |
24 ms |
1144 KB |
Output is correct |
44 |
Correct |
24 ms |
1184 KB |
Output is correct |
45 |
Correct |
25 ms |
1144 KB |
Output is correct |
46 |
Correct |
26 ms |
760 KB |
Output is correct |
47 |
Correct |
29 ms |
888 KB |
Output is correct |
48 |
Correct |
20 ms |
1272 KB |
Output is correct |
49 |
Correct |
18 ms |
1016 KB |
Output is correct |
50 |
Correct |
31 ms |
760 KB |
Output is correct |
51 |
Correct |
9 ms |
508 KB |
Output is correct |
52 |
Correct |
26 ms |
1272 KB |
Output is correct |
53 |
Correct |
43 ms |
1016 KB |
Output is correct |
54 |
Correct |
55 ms |
1144 KB |
Output is correct |
55 |
Correct |
49 ms |
2008 KB |
Output is correct |
56 |
Correct |
56 ms |
1272 KB |
Output is correct |
57 |
Correct |
54 ms |
2092 KB |
Output is correct |
58 |
Correct |
78 ms |
1376 KB |
Output is correct |
59 |
Correct |
68 ms |
1652 KB |
Output is correct |
60 |
Correct |
21 ms |
632 KB |
Output is correct |
61 |
Correct |
76 ms |
1780 KB |
Output is correct |
62 |
Correct |
59 ms |
1780 KB |
Output is correct |
63 |
Correct |
52 ms |
1908 KB |
Output is correct |
64 |
Correct |
64 ms |
1908 KB |
Output is correct |
65 |
Correct |
19 ms |
888 KB |
Output is correct |
66 |
Correct |
26 ms |
1016 KB |
Output is correct |
67 |
Correct |
107 ms |
1652 KB |
Output is correct |
68 |
Correct |
58 ms |
908 KB |
Output is correct |
69 |
Correct |
138 ms |
3532 KB |
Output is correct |
70 |
Correct |
229 ms |
2304 KB |
Output is correct |
71 |
Correct |
222 ms |
2292 KB |
Output is correct |
72 |
Correct |
285 ms |
1908 KB |
Output is correct |
73 |
Correct |
284 ms |
1908 KB |
Output is correct |
74 |
Correct |
172 ms |
3924 KB |
Output is correct |
75 |
Correct |
215 ms |
3272 KB |
Output is correct |
76 |
Correct |
137 ms |
3884 KB |
Output is correct |
77 |
Correct |
151 ms |
3936 KB |
Output is correct |