#pragma GCC optimize("O3")
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
using namespace std;
#define IShowSpeed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define popcnt __builtin_popcount
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define mii map<int,int>
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define pb push_back
#define vt vector
#define endl '\n'
#define X first
#define Y second
typedef long double ld;
typedef long long ll;
const ll dx[4]={1,-1,0,0},dy[4]={0,0,1,-1},N=1e6;
const ll mod=1e9+7,inf=1e18;
int dp[N];
void solve(){
int n;
cin>>n;
int a[n+2],sum=0;
for(int i=1; i<=n; ++i) {cin>>a[i];sum+=a[i];}
dp[0]=1;
mii used;
for(int j=1; j<=n; ++j) for(int i=sum; i>=a[j]; --i) dp[i]+=dp[i-a[j]];
if(!dp[sum/2] || sum%2){
cout<<0<<endl;
return;
}
vt<int>res;
for(int i=1; i<=n; ++i){
for(int j=a[i]; j<=sum; ++j) dp[j]-=dp[j-a[i]];
for(int nd=1; nd<=sum; ++nd){
int h=sum-a[i];
h+=nd;
if(h%2 || !dp[h/2]) continue;
used[nd]++;
if(used[nd]==n)res.pb(nd);
}
for(int j=sum; j>=a[i]; --j) dp[j]+=dp[j-a[i]];
}
cout<<res.size()<<endl;
for(int x:res)cout<<x<<' ';
}
int main() {
IShowSpeed;
int tt=1;
//cin>>tt;
while(tt--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 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 |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 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 |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 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 |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
10 ms |
408 KB |
Output is correct |
22 |
Correct |
11 ms |
332 KB |
Output is correct |
23 |
Correct |
5 ms |
332 KB |
Output is correct |
24 |
Correct |
19 ms |
444 KB |
Output is correct |
25 |
Correct |
33 ms |
532 KB |
Output is correct |
26 |
Correct |
36 ms |
580 KB |
Output is correct |
27 |
Correct |
20 ms |
448 KB |
Output is correct |
28 |
Correct |
18 ms |
460 KB |
Output is correct |
29 |
Correct |
26 ms |
460 KB |
Output is correct |
30 |
Correct |
27 ms |
588 KB |
Output is correct |
31 |
Correct |
36 ms |
524 KB |
Output is correct |
32 |
Correct |
21 ms |
460 KB |
Output is correct |
33 |
Correct |
3 ms |
332 KB |
Output is correct |
34 |
Correct |
3 ms |
332 KB |
Output is correct |
35 |
Correct |
20 ms |
460 KB |
Output is correct |
36 |
Correct |
20 ms |
444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 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 |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
10 ms |
408 KB |
Output is correct |
22 |
Correct |
11 ms |
332 KB |
Output is correct |
23 |
Correct |
5 ms |
332 KB |
Output is correct |
24 |
Correct |
19 ms |
444 KB |
Output is correct |
25 |
Correct |
33 ms |
532 KB |
Output is correct |
26 |
Correct |
36 ms |
580 KB |
Output is correct |
27 |
Correct |
20 ms |
448 KB |
Output is correct |
28 |
Correct |
18 ms |
460 KB |
Output is correct |
29 |
Correct |
26 ms |
460 KB |
Output is correct |
30 |
Correct |
27 ms |
588 KB |
Output is correct |
31 |
Correct |
36 ms |
524 KB |
Output is correct |
32 |
Correct |
21 ms |
460 KB |
Output is correct |
33 |
Correct |
3 ms |
332 KB |
Output is correct |
34 |
Correct |
3 ms |
332 KB |
Output is correct |
35 |
Correct |
20 ms |
460 KB |
Output is correct |
36 |
Correct |
20 ms |
444 KB |
Output is correct |
37 |
Correct |
218 ms |
964 KB |
Output is correct |
38 |
Correct |
251 ms |
972 KB |
Output is correct |
39 |
Correct |
43 ms |
460 KB |
Output is correct |
40 |
Correct |
481 ms |
1316 KB |
Output is correct |
41 |
Correct |
55 ms |
588 KB |
Output is correct |
42 |
Correct |
406 ms |
1252 KB |
Output is correct |
43 |
Correct |
807 ms |
2168 KB |
Output is correct |
44 |
Correct |
810 ms |
2204 KB |
Output is correct |
45 |
Correct |
885 ms |
2212 KB |
Output is correct |
46 |
Correct |
240 ms |
1164 KB |
Output is correct |
47 |
Correct |
453 ms |
1320 KB |
Output is correct |
48 |
Correct |
643 ms |
2080 KB |
Output is correct |
49 |
Correct |
430 ms |
1692 KB |
Output is correct |
50 |
Correct |
499 ms |
1348 KB |
Output is correct |
51 |
Correct |
2 ms |
332 KB |
Output is correct |
52 |
Correct |
976 ms |
2520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 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 |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
10 ms |
408 KB |
Output is correct |
22 |
Correct |
11 ms |
332 KB |
Output is correct |
23 |
Correct |
5 ms |
332 KB |
Output is correct |
24 |
Correct |
19 ms |
444 KB |
Output is correct |
25 |
Correct |
33 ms |
532 KB |
Output is correct |
26 |
Correct |
36 ms |
580 KB |
Output is correct |
27 |
Correct |
20 ms |
448 KB |
Output is correct |
28 |
Correct |
18 ms |
460 KB |
Output is correct |
29 |
Correct |
26 ms |
460 KB |
Output is correct |
30 |
Correct |
27 ms |
588 KB |
Output is correct |
31 |
Correct |
36 ms |
524 KB |
Output is correct |
32 |
Correct |
21 ms |
460 KB |
Output is correct |
33 |
Correct |
3 ms |
332 KB |
Output is correct |
34 |
Correct |
3 ms |
332 KB |
Output is correct |
35 |
Correct |
20 ms |
460 KB |
Output is correct |
36 |
Correct |
20 ms |
444 KB |
Output is correct |
37 |
Correct |
218 ms |
964 KB |
Output is correct |
38 |
Correct |
251 ms |
972 KB |
Output is correct |
39 |
Correct |
43 ms |
460 KB |
Output is correct |
40 |
Correct |
481 ms |
1316 KB |
Output is correct |
41 |
Correct |
55 ms |
588 KB |
Output is correct |
42 |
Correct |
406 ms |
1252 KB |
Output is correct |
43 |
Correct |
807 ms |
2168 KB |
Output is correct |
44 |
Correct |
810 ms |
2204 KB |
Output is correct |
45 |
Correct |
885 ms |
2212 KB |
Output is correct |
46 |
Correct |
240 ms |
1164 KB |
Output is correct |
47 |
Correct |
453 ms |
1320 KB |
Output is correct |
48 |
Correct |
643 ms |
2080 KB |
Output is correct |
49 |
Correct |
430 ms |
1692 KB |
Output is correct |
50 |
Correct |
499 ms |
1348 KB |
Output is correct |
51 |
Correct |
2 ms |
332 KB |
Output is correct |
52 |
Correct |
976 ms |
2520 KB |
Output is correct |
53 |
Correct |
779 ms |
1860 KB |
Output is correct |
54 |
Execution timed out |
1055 ms |
1828 KB |
Time limit exceeded |
55 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 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 |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
10 ms |
408 KB |
Output is correct |
22 |
Correct |
11 ms |
332 KB |
Output is correct |
23 |
Correct |
5 ms |
332 KB |
Output is correct |
24 |
Correct |
19 ms |
444 KB |
Output is correct |
25 |
Correct |
33 ms |
532 KB |
Output is correct |
26 |
Correct |
36 ms |
580 KB |
Output is correct |
27 |
Correct |
20 ms |
448 KB |
Output is correct |
28 |
Correct |
18 ms |
460 KB |
Output is correct |
29 |
Correct |
26 ms |
460 KB |
Output is correct |
30 |
Correct |
27 ms |
588 KB |
Output is correct |
31 |
Correct |
36 ms |
524 KB |
Output is correct |
32 |
Correct |
21 ms |
460 KB |
Output is correct |
33 |
Correct |
3 ms |
332 KB |
Output is correct |
34 |
Correct |
3 ms |
332 KB |
Output is correct |
35 |
Correct |
20 ms |
460 KB |
Output is correct |
36 |
Correct |
20 ms |
444 KB |
Output is correct |
37 |
Correct |
218 ms |
964 KB |
Output is correct |
38 |
Correct |
251 ms |
972 KB |
Output is correct |
39 |
Correct |
43 ms |
460 KB |
Output is correct |
40 |
Correct |
481 ms |
1316 KB |
Output is correct |
41 |
Correct |
55 ms |
588 KB |
Output is correct |
42 |
Correct |
406 ms |
1252 KB |
Output is correct |
43 |
Correct |
807 ms |
2168 KB |
Output is correct |
44 |
Correct |
810 ms |
2204 KB |
Output is correct |
45 |
Correct |
885 ms |
2212 KB |
Output is correct |
46 |
Correct |
240 ms |
1164 KB |
Output is correct |
47 |
Correct |
453 ms |
1320 KB |
Output is correct |
48 |
Correct |
643 ms |
2080 KB |
Output is correct |
49 |
Correct |
430 ms |
1692 KB |
Output is correct |
50 |
Correct |
499 ms |
1348 KB |
Output is correct |
51 |
Correct |
2 ms |
332 KB |
Output is correct |
52 |
Correct |
976 ms |
2520 KB |
Output is correct |
53 |
Correct |
779 ms |
1860 KB |
Output is correct |
54 |
Execution timed out |
1055 ms |
1828 KB |
Time limit exceeded |
55 |
Halted |
0 ms |
0 KB |
- |