#include<bits/stdc++.h>
using namespace std;
int n,tot;
int a[505];
bitset<500005> dp[505];
int variante[500005],cntv;
int newv[500005],cntnew;
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
tot+=a[i];
}
for(int i=1;i<=tot;i++)
variante[++cntv]=i;
dp[0][250000]=1;
for(int i=0;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i==j)
dp[j] = dp[j-1];
else
dp[j] = ((dp[j-1]<<a[j])|(dp[j-1]>>a[j]));
}
if(i==0)
{
if(dp[n][250000]==0)
{
cntv=0;
break;
}
continue;
}
cntnew=0;
for(int j=1;j<=cntv;j++)
{
int x = variante[j];
if(dp[n][x+250000] || dp[n][-x+250000])
newv[++cntnew] = x;
///difs = -x
///difs = x
}
cntv=cntnew;
for(int j=1;j<=cntnew;j++)
variante[j] = newv[j];
}
cout<<cntv<<"\n";
for(int i=1;i<=cntv;i++)
cout<<variante[i]<<" ";
return 0;
}
/**
3
2 2 2
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
2 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2904 KB |
Output is correct |
5 |
Correct |
4 ms |
4700 KB |
Output is correct |
6 |
Correct |
2 ms |
4700 KB |
Output is correct |
7 |
Correct |
2 ms |
4700 KB |
Output is correct |
8 |
Correct |
4 ms |
4700 KB |
Output is correct |
9 |
Correct |
3 ms |
4696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
2 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2904 KB |
Output is correct |
5 |
Correct |
4 ms |
4700 KB |
Output is correct |
6 |
Correct |
2 ms |
4700 KB |
Output is correct |
7 |
Correct |
2 ms |
4700 KB |
Output is correct |
8 |
Correct |
4 ms |
4700 KB |
Output is correct |
9 |
Correct |
3 ms |
4696 KB |
Output is correct |
10 |
Correct |
20 ms |
4700 KB |
Output is correct |
11 |
Correct |
20 ms |
4760 KB |
Output is correct |
12 |
Correct |
20 ms |
4700 KB |
Output is correct |
13 |
Correct |
16 ms |
4696 KB |
Output is correct |
14 |
Correct |
18 ms |
4700 KB |
Output is correct |
15 |
Correct |
18 ms |
4700 KB |
Output is correct |
16 |
Correct |
20 ms |
4700 KB |
Output is correct |
17 |
Correct |
8 ms |
4712 KB |
Output is correct |
18 |
Correct |
13 ms |
4700 KB |
Output is correct |
19 |
Correct |
15 ms |
4752 KB |
Output is correct |
20 |
Correct |
20 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
2 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2904 KB |
Output is correct |
5 |
Correct |
4 ms |
4700 KB |
Output is correct |
6 |
Correct |
2 ms |
4700 KB |
Output is correct |
7 |
Correct |
2 ms |
4700 KB |
Output is correct |
8 |
Correct |
4 ms |
4700 KB |
Output is correct |
9 |
Correct |
3 ms |
4696 KB |
Output is correct |
10 |
Correct |
20 ms |
4700 KB |
Output is correct |
11 |
Correct |
20 ms |
4760 KB |
Output is correct |
12 |
Correct |
20 ms |
4700 KB |
Output is correct |
13 |
Correct |
16 ms |
4696 KB |
Output is correct |
14 |
Correct |
18 ms |
4700 KB |
Output is correct |
15 |
Correct |
18 ms |
4700 KB |
Output is correct |
16 |
Correct |
20 ms |
4700 KB |
Output is correct |
17 |
Correct |
8 ms |
4712 KB |
Output is correct |
18 |
Correct |
13 ms |
4700 KB |
Output is correct |
19 |
Correct |
15 ms |
4752 KB |
Output is correct |
20 |
Correct |
20 ms |
4700 KB |
Output is correct |
21 |
Correct |
91 ms |
6744 KB |
Output is correct |
22 |
Correct |
120 ms |
8796 KB |
Output is correct |
23 |
Correct |
61 ms |
6996 KB |
Output is correct |
24 |
Correct |
191 ms |
8864 KB |
Output is correct |
25 |
Correct |
192 ms |
8792 KB |
Output is correct |
26 |
Correct |
214 ms |
8904 KB |
Output is correct |
27 |
Correct |
217 ms |
8876 KB |
Output is correct |
28 |
Correct |
221 ms |
8880 KB |
Output is correct |
29 |
Correct |
217 ms |
9044 KB |
Output is correct |
30 |
Correct |
213 ms |
8792 KB |
Output is correct |
31 |
Correct |
216 ms |
9048 KB |
Output is correct |
32 |
Correct |
237 ms |
8872 KB |
Output is correct |
33 |
Correct |
216 ms |
8792 KB |
Output is correct |
34 |
Correct |
215 ms |
8796 KB |
Output is correct |
35 |
Correct |
225 ms |
9044 KB |
Output is correct |
36 |
Correct |
215 ms |
8792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
2 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2904 KB |
Output is correct |
5 |
Correct |
4 ms |
4700 KB |
Output is correct |
6 |
Correct |
2 ms |
4700 KB |
Output is correct |
7 |
Correct |
2 ms |
4700 KB |
Output is correct |
8 |
Correct |
4 ms |
4700 KB |
Output is correct |
9 |
Correct |
3 ms |
4696 KB |
Output is correct |
10 |
Correct |
20 ms |
4700 KB |
Output is correct |
11 |
Correct |
20 ms |
4760 KB |
Output is correct |
12 |
Correct |
20 ms |
4700 KB |
Output is correct |
13 |
Correct |
16 ms |
4696 KB |
Output is correct |
14 |
Correct |
18 ms |
4700 KB |
Output is correct |
15 |
Correct |
18 ms |
4700 KB |
Output is correct |
16 |
Correct |
20 ms |
4700 KB |
Output is correct |
17 |
Correct |
8 ms |
4712 KB |
Output is correct |
18 |
Correct |
13 ms |
4700 KB |
Output is correct |
19 |
Correct |
15 ms |
4752 KB |
Output is correct |
20 |
Correct |
20 ms |
4700 KB |
Output is correct |
21 |
Correct |
91 ms |
6744 KB |
Output is correct |
22 |
Correct |
120 ms |
8796 KB |
Output is correct |
23 |
Correct |
61 ms |
6996 KB |
Output is correct |
24 |
Correct |
191 ms |
8864 KB |
Output is correct |
25 |
Correct |
192 ms |
8792 KB |
Output is correct |
26 |
Correct |
214 ms |
8904 KB |
Output is correct |
27 |
Correct |
217 ms |
8876 KB |
Output is correct |
28 |
Correct |
221 ms |
8880 KB |
Output is correct |
29 |
Correct |
217 ms |
9044 KB |
Output is correct |
30 |
Correct |
213 ms |
8792 KB |
Output is correct |
31 |
Correct |
216 ms |
9048 KB |
Output is correct |
32 |
Correct |
237 ms |
8872 KB |
Output is correct |
33 |
Correct |
216 ms |
8792 KB |
Output is correct |
34 |
Correct |
215 ms |
8796 KB |
Output is correct |
35 |
Correct |
225 ms |
9044 KB |
Output is correct |
36 |
Correct |
215 ms |
8792 KB |
Output is correct |
37 |
Correct |
887 ms |
15104 KB |
Output is correct |
38 |
Correct |
882 ms |
15104 KB |
Output is correct |
39 |
Execution timed out |
1032 ms |
19288 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
2 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2904 KB |
Output is correct |
5 |
Correct |
4 ms |
4700 KB |
Output is correct |
6 |
Correct |
2 ms |
4700 KB |
Output is correct |
7 |
Correct |
2 ms |
4700 KB |
Output is correct |
8 |
Correct |
4 ms |
4700 KB |
Output is correct |
9 |
Correct |
3 ms |
4696 KB |
Output is correct |
10 |
Correct |
20 ms |
4700 KB |
Output is correct |
11 |
Correct |
20 ms |
4760 KB |
Output is correct |
12 |
Correct |
20 ms |
4700 KB |
Output is correct |
13 |
Correct |
16 ms |
4696 KB |
Output is correct |
14 |
Correct |
18 ms |
4700 KB |
Output is correct |
15 |
Correct |
18 ms |
4700 KB |
Output is correct |
16 |
Correct |
20 ms |
4700 KB |
Output is correct |
17 |
Correct |
8 ms |
4712 KB |
Output is correct |
18 |
Correct |
13 ms |
4700 KB |
Output is correct |
19 |
Correct |
15 ms |
4752 KB |
Output is correct |
20 |
Correct |
20 ms |
4700 KB |
Output is correct |
21 |
Correct |
91 ms |
6744 KB |
Output is correct |
22 |
Correct |
120 ms |
8796 KB |
Output is correct |
23 |
Correct |
61 ms |
6996 KB |
Output is correct |
24 |
Correct |
191 ms |
8864 KB |
Output is correct |
25 |
Correct |
192 ms |
8792 KB |
Output is correct |
26 |
Correct |
214 ms |
8904 KB |
Output is correct |
27 |
Correct |
217 ms |
8876 KB |
Output is correct |
28 |
Correct |
221 ms |
8880 KB |
Output is correct |
29 |
Correct |
217 ms |
9044 KB |
Output is correct |
30 |
Correct |
213 ms |
8792 KB |
Output is correct |
31 |
Correct |
216 ms |
9048 KB |
Output is correct |
32 |
Correct |
237 ms |
8872 KB |
Output is correct |
33 |
Correct |
216 ms |
8792 KB |
Output is correct |
34 |
Correct |
215 ms |
8796 KB |
Output is correct |
35 |
Correct |
225 ms |
9044 KB |
Output is correct |
36 |
Correct |
215 ms |
8792 KB |
Output is correct |
37 |
Correct |
887 ms |
15104 KB |
Output is correct |
38 |
Correct |
882 ms |
15104 KB |
Output is correct |
39 |
Execution timed out |
1032 ms |
19288 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
2 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2904 KB |
Output is correct |
5 |
Correct |
4 ms |
4700 KB |
Output is correct |
6 |
Correct |
2 ms |
4700 KB |
Output is correct |
7 |
Correct |
2 ms |
4700 KB |
Output is correct |
8 |
Correct |
4 ms |
4700 KB |
Output is correct |
9 |
Correct |
3 ms |
4696 KB |
Output is correct |
10 |
Correct |
20 ms |
4700 KB |
Output is correct |
11 |
Correct |
20 ms |
4760 KB |
Output is correct |
12 |
Correct |
20 ms |
4700 KB |
Output is correct |
13 |
Correct |
16 ms |
4696 KB |
Output is correct |
14 |
Correct |
18 ms |
4700 KB |
Output is correct |
15 |
Correct |
18 ms |
4700 KB |
Output is correct |
16 |
Correct |
20 ms |
4700 KB |
Output is correct |
17 |
Correct |
8 ms |
4712 KB |
Output is correct |
18 |
Correct |
13 ms |
4700 KB |
Output is correct |
19 |
Correct |
15 ms |
4752 KB |
Output is correct |
20 |
Correct |
20 ms |
4700 KB |
Output is correct |
21 |
Correct |
91 ms |
6744 KB |
Output is correct |
22 |
Correct |
120 ms |
8796 KB |
Output is correct |
23 |
Correct |
61 ms |
6996 KB |
Output is correct |
24 |
Correct |
191 ms |
8864 KB |
Output is correct |
25 |
Correct |
192 ms |
8792 KB |
Output is correct |
26 |
Correct |
214 ms |
8904 KB |
Output is correct |
27 |
Correct |
217 ms |
8876 KB |
Output is correct |
28 |
Correct |
221 ms |
8880 KB |
Output is correct |
29 |
Correct |
217 ms |
9044 KB |
Output is correct |
30 |
Correct |
213 ms |
8792 KB |
Output is correct |
31 |
Correct |
216 ms |
9048 KB |
Output is correct |
32 |
Correct |
237 ms |
8872 KB |
Output is correct |
33 |
Correct |
216 ms |
8792 KB |
Output is correct |
34 |
Correct |
215 ms |
8796 KB |
Output is correct |
35 |
Correct |
225 ms |
9044 KB |
Output is correct |
36 |
Correct |
215 ms |
8792 KB |
Output is correct |
37 |
Correct |
887 ms |
15104 KB |
Output is correct |
38 |
Correct |
882 ms |
15104 KB |
Output is correct |
39 |
Execution timed out |
1032 ms |
19288 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |