#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9
using namespace std;
typedef long long ll;
int add(int a, int b)
{
ll x = a+b;
if(x >= mod)
x -= mod;
if(x < 0)
x += mod;
return x;
}
ll mul(ll a, ll b)
{
return (a*b) % mod;
}
ll pw(ll a, ll b)
{
ll ans = 1;
while(b)
{
if(b & 1)
ans = (ans * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return ans;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand_seed()
{
long long a = rng();
return a;
}
int n;
int v[502];
int frq[1000002];
bool dp[250002];
int ct[250002], ct2[250002];
int fi[250002];
int lst[250002];
bool canruk(int lack)
{
int sm = 0;
for(int i = 1; i <= n; ++i)
if(i != lack)
sm += v[i];
if(lack == 0)
{
int mxval = 0;
dp[0] = 1;
ct[0] = 1;
for(int i = 1; i <= n; ++i)
{
for(int j = mxval; j >= 0; --j)
if(dp[j])
{
ct[j + v[i]] = add(ct[j + v[i]], ct[j]);
if(!fi[j + v[i]])
fi[j + v[i]] = i;
lst[j + v[i]] = i;
dp[j + v[i]] = 1;
}
mxval += v[i];
}
// for(int i = 0; i <= mxval; ++i)
// cout << ct[i] << " ";
// cout << '\n';
if(mxval % 2 == 0 && dp[mxval / 2])
return 1;
return 0;
}
else
{
for(int j = 0; j <= sm + v[lack]; ++j)
ct2[j] = ct[j];
for(int j = v[lack]; j <= sm + v[lack]; ++j)
ct[j] = add(ct[j], -ct[j - v[lack]]);
// for(int i = 0; i <= sm + v[lack]; ++i)
// cout << ct[i] << " ";
// cout << '\n';
for(int i = 0; i <= sm/2; ++i)
if(ct[i])
frq[sm - 2 * i]++;
for(int j = 0; j <= sm + v[lack]; ++j)
ct[j] = ct2[j];
return 1;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for(int i = 1; i <= n; ++i)
cin >> v[i];
sort(v+1, v+n+1);
if(!canruk(0))
{
cout << 0;
return 0;
}
for(int i = 1; i <= n; ++i)
canruk(i);
int nrok = 0;
for(int i = 0; i <= 1000000; ++i)
if(frq[i] == n)
++nrok;
cout << nrok << '\n';
for(int i = 0; i <= 1000000; ++i)
if(frq[i] == n)
cout << i << " ";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
248 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Correct |
4 ms |
376 KB |
Output is correct |
7 |
Correct |
4 ms |
376 KB |
Output is correct |
8 |
Correct |
4 ms |
376 KB |
Output is correct |
9 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
248 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Correct |
4 ms |
376 KB |
Output is correct |
7 |
Correct |
4 ms |
376 KB |
Output is correct |
8 |
Correct |
4 ms |
376 KB |
Output is correct |
9 |
Correct |
4 ms |
376 KB |
Output is correct |
10 |
Correct |
4 ms |
376 KB |
Output is correct |
11 |
Correct |
4 ms |
424 KB |
Output is correct |
12 |
Correct |
4 ms |
376 KB |
Output is correct |
13 |
Correct |
4 ms |
376 KB |
Output is correct |
14 |
Correct |
4 ms |
376 KB |
Output is correct |
15 |
Correct |
4 ms |
376 KB |
Output is correct |
16 |
Correct |
4 ms |
376 KB |
Output is correct |
17 |
Correct |
4 ms |
376 KB |
Output is correct |
18 |
Correct |
4 ms |
376 KB |
Output is correct |
19 |
Correct |
4 ms |
376 KB |
Output is correct |
20 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
248 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Correct |
4 ms |
376 KB |
Output is correct |
7 |
Correct |
4 ms |
376 KB |
Output is correct |
8 |
Correct |
4 ms |
376 KB |
Output is correct |
9 |
Correct |
4 ms |
376 KB |
Output is correct |
10 |
Correct |
4 ms |
376 KB |
Output is correct |
11 |
Correct |
4 ms |
424 KB |
Output is correct |
12 |
Correct |
4 ms |
376 KB |
Output is correct |
13 |
Correct |
4 ms |
376 KB |
Output is correct |
14 |
Correct |
4 ms |
376 KB |
Output is correct |
15 |
Correct |
4 ms |
376 KB |
Output is correct |
16 |
Correct |
4 ms |
376 KB |
Output is correct |
17 |
Correct |
4 ms |
376 KB |
Output is correct |
18 |
Correct |
4 ms |
376 KB |
Output is correct |
19 |
Correct |
4 ms |
376 KB |
Output is correct |
20 |
Correct |
4 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
504 KB |
Output is correct |
22 |
Correct |
5 ms |
504 KB |
Output is correct |
23 |
Correct |
5 ms |
504 KB |
Output is correct |
24 |
Correct |
7 ms |
504 KB |
Output is correct |
25 |
Correct |
8 ms |
504 KB |
Output is correct |
26 |
Correct |
9 ms |
632 KB |
Output is correct |
27 |
Correct |
8 ms |
632 KB |
Output is correct |
28 |
Correct |
8 ms |
632 KB |
Output is correct |
29 |
Correct |
8 ms |
632 KB |
Output is correct |
30 |
Correct |
7 ms |
504 KB |
Output is correct |
31 |
Correct |
8 ms |
632 KB |
Output is correct |
32 |
Correct |
7 ms |
504 KB |
Output is correct |
33 |
Correct |
19 ms |
504 KB |
Output is correct |
34 |
Correct |
7 ms |
632 KB |
Output is correct |
35 |
Correct |
8 ms |
632 KB |
Output is correct |
36 |
Correct |
7 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
248 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Correct |
4 ms |
376 KB |
Output is correct |
7 |
Correct |
4 ms |
376 KB |
Output is correct |
8 |
Correct |
4 ms |
376 KB |
Output is correct |
9 |
Correct |
4 ms |
376 KB |
Output is correct |
10 |
Correct |
4 ms |
376 KB |
Output is correct |
11 |
Correct |
4 ms |
424 KB |
Output is correct |
12 |
Correct |
4 ms |
376 KB |
Output is correct |
13 |
Correct |
4 ms |
376 KB |
Output is correct |
14 |
Correct |
4 ms |
376 KB |
Output is correct |
15 |
Correct |
4 ms |
376 KB |
Output is correct |
16 |
Correct |
4 ms |
376 KB |
Output is correct |
17 |
Correct |
4 ms |
376 KB |
Output is correct |
18 |
Correct |
4 ms |
376 KB |
Output is correct |
19 |
Correct |
4 ms |
376 KB |
Output is correct |
20 |
Correct |
4 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
504 KB |
Output is correct |
22 |
Correct |
5 ms |
504 KB |
Output is correct |
23 |
Correct |
5 ms |
504 KB |
Output is correct |
24 |
Correct |
7 ms |
504 KB |
Output is correct |
25 |
Correct |
8 ms |
504 KB |
Output is correct |
26 |
Correct |
9 ms |
632 KB |
Output is correct |
27 |
Correct |
8 ms |
632 KB |
Output is correct |
28 |
Correct |
8 ms |
632 KB |
Output is correct |
29 |
Correct |
8 ms |
632 KB |
Output is correct |
30 |
Correct |
7 ms |
504 KB |
Output is correct |
31 |
Correct |
8 ms |
632 KB |
Output is correct |
32 |
Correct |
7 ms |
504 KB |
Output is correct |
33 |
Correct |
19 ms |
504 KB |
Output is correct |
34 |
Correct |
7 ms |
632 KB |
Output is correct |
35 |
Correct |
8 ms |
632 KB |
Output is correct |
36 |
Correct |
7 ms |
504 KB |
Output is correct |
37 |
Correct |
27 ms |
888 KB |
Output is correct |
38 |
Correct |
28 ms |
888 KB |
Output is correct |
39 |
Correct |
51 ms |
1756 KB |
Output is correct |
40 |
Correct |
52 ms |
1068 KB |
Output is correct |
41 |
Correct |
64 ms |
1912 KB |
Output is correct |
42 |
Correct |
45 ms |
1032 KB |
Output is correct |
43 |
Correct |
87 ms |
1656 KB |
Output is correct |
44 |
Correct |
91 ms |
1724 KB |
Output is correct |
45 |
Correct |
92 ms |
1656 KB |
Output is correct |
46 |
Correct |
38 ms |
1016 KB |
Output is correct |
47 |
Correct |
50 ms |
1144 KB |
Output is correct |
48 |
Correct |
79 ms |
1756 KB |
Output is correct |
49 |
Correct |
65 ms |
1656 KB |
Output is correct |
50 |
Correct |
50 ms |
1144 KB |
Output is correct |
51 |
Correct |
23 ms |
760 KB |
Output is correct |
52 |
Correct |
112 ms |
2044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
248 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Correct |
4 ms |
376 KB |
Output is correct |
7 |
Correct |
4 ms |
376 KB |
Output is correct |
8 |
Correct |
4 ms |
376 KB |
Output is correct |
9 |
Correct |
4 ms |
376 KB |
Output is correct |
10 |
Correct |
4 ms |
376 KB |
Output is correct |
11 |
Correct |
4 ms |
424 KB |
Output is correct |
12 |
Correct |
4 ms |
376 KB |
Output is correct |
13 |
Correct |
4 ms |
376 KB |
Output is correct |
14 |
Correct |
4 ms |
376 KB |
Output is correct |
15 |
Correct |
4 ms |
376 KB |
Output is correct |
16 |
Correct |
4 ms |
376 KB |
Output is correct |
17 |
Correct |
4 ms |
376 KB |
Output is correct |
18 |
Correct |
4 ms |
376 KB |
Output is correct |
19 |
Correct |
4 ms |
376 KB |
Output is correct |
20 |
Correct |
4 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
504 KB |
Output is correct |
22 |
Correct |
5 ms |
504 KB |
Output is correct |
23 |
Correct |
5 ms |
504 KB |
Output is correct |
24 |
Correct |
7 ms |
504 KB |
Output is correct |
25 |
Correct |
8 ms |
504 KB |
Output is correct |
26 |
Correct |
9 ms |
632 KB |
Output is correct |
27 |
Correct |
8 ms |
632 KB |
Output is correct |
28 |
Correct |
8 ms |
632 KB |
Output is correct |
29 |
Correct |
8 ms |
632 KB |
Output is correct |
30 |
Correct |
7 ms |
504 KB |
Output is correct |
31 |
Correct |
8 ms |
632 KB |
Output is correct |
32 |
Correct |
7 ms |
504 KB |
Output is correct |
33 |
Correct |
19 ms |
504 KB |
Output is correct |
34 |
Correct |
7 ms |
632 KB |
Output is correct |
35 |
Correct |
8 ms |
632 KB |
Output is correct |
36 |
Correct |
7 ms |
504 KB |
Output is correct |
37 |
Correct |
27 ms |
888 KB |
Output is correct |
38 |
Correct |
28 ms |
888 KB |
Output is correct |
39 |
Correct |
51 ms |
1756 KB |
Output is correct |
40 |
Correct |
52 ms |
1068 KB |
Output is correct |
41 |
Correct |
64 ms |
1912 KB |
Output is correct |
42 |
Correct |
45 ms |
1032 KB |
Output is correct |
43 |
Correct |
87 ms |
1656 KB |
Output is correct |
44 |
Correct |
91 ms |
1724 KB |
Output is correct |
45 |
Correct |
92 ms |
1656 KB |
Output is correct |
46 |
Correct |
38 ms |
1016 KB |
Output is correct |
47 |
Correct |
50 ms |
1144 KB |
Output is correct |
48 |
Correct |
79 ms |
1756 KB |
Output is correct |
49 |
Correct |
65 ms |
1656 KB |
Output is correct |
50 |
Correct |
50 ms |
1144 KB |
Output is correct |
51 |
Correct |
23 ms |
760 KB |
Output is correct |
52 |
Correct |
112 ms |
2044 KB |
Output is correct |
53 |
Correct |
82 ms |
1528 KB |
Output is correct |
54 |
Correct |
117 ms |
1656 KB |
Output is correct |
55 |
Correct |
235 ms |
2936 KB |
Output is correct |
56 |
Correct |
103 ms |
1784 KB |
Output is correct |
57 |
Correct |
250 ms |
3124 KB |
Output is correct |
58 |
Correct |
124 ms |
1840 KB |
Output is correct |
59 |
Correct |
170 ms |
2136 KB |
Output is correct |
60 |
Correct |
61 ms |
1144 KB |
Output is correct |
61 |
Correct |
192 ms |
2424 KB |
Output is correct |
62 |
Correct |
200 ms |
2652 KB |
Output is correct |
63 |
Correct |
209 ms |
2808 KB |
Output is correct |
64 |
Correct |
206 ms |
2772 KB |
Output is correct |
65 |
Correct |
57 ms |
1372 KB |
Output is correct |
66 |
Correct |
65 ms |
1528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
248 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Correct |
4 ms |
376 KB |
Output is correct |
7 |
Correct |
4 ms |
376 KB |
Output is correct |
8 |
Correct |
4 ms |
376 KB |
Output is correct |
9 |
Correct |
4 ms |
376 KB |
Output is correct |
10 |
Correct |
4 ms |
376 KB |
Output is correct |
11 |
Correct |
4 ms |
424 KB |
Output is correct |
12 |
Correct |
4 ms |
376 KB |
Output is correct |
13 |
Correct |
4 ms |
376 KB |
Output is correct |
14 |
Correct |
4 ms |
376 KB |
Output is correct |
15 |
Correct |
4 ms |
376 KB |
Output is correct |
16 |
Correct |
4 ms |
376 KB |
Output is correct |
17 |
Correct |
4 ms |
376 KB |
Output is correct |
18 |
Correct |
4 ms |
376 KB |
Output is correct |
19 |
Correct |
4 ms |
376 KB |
Output is correct |
20 |
Correct |
4 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
504 KB |
Output is correct |
22 |
Correct |
5 ms |
504 KB |
Output is correct |
23 |
Correct |
5 ms |
504 KB |
Output is correct |
24 |
Correct |
7 ms |
504 KB |
Output is correct |
25 |
Correct |
8 ms |
504 KB |
Output is correct |
26 |
Correct |
9 ms |
632 KB |
Output is correct |
27 |
Correct |
8 ms |
632 KB |
Output is correct |
28 |
Correct |
8 ms |
632 KB |
Output is correct |
29 |
Correct |
8 ms |
632 KB |
Output is correct |
30 |
Correct |
7 ms |
504 KB |
Output is correct |
31 |
Correct |
8 ms |
632 KB |
Output is correct |
32 |
Correct |
7 ms |
504 KB |
Output is correct |
33 |
Correct |
19 ms |
504 KB |
Output is correct |
34 |
Correct |
7 ms |
632 KB |
Output is correct |
35 |
Correct |
8 ms |
632 KB |
Output is correct |
36 |
Correct |
7 ms |
504 KB |
Output is correct |
37 |
Correct |
27 ms |
888 KB |
Output is correct |
38 |
Correct |
28 ms |
888 KB |
Output is correct |
39 |
Correct |
51 ms |
1756 KB |
Output is correct |
40 |
Correct |
52 ms |
1068 KB |
Output is correct |
41 |
Correct |
64 ms |
1912 KB |
Output is correct |
42 |
Correct |
45 ms |
1032 KB |
Output is correct |
43 |
Correct |
87 ms |
1656 KB |
Output is correct |
44 |
Correct |
91 ms |
1724 KB |
Output is correct |
45 |
Correct |
92 ms |
1656 KB |
Output is correct |
46 |
Correct |
38 ms |
1016 KB |
Output is correct |
47 |
Correct |
50 ms |
1144 KB |
Output is correct |
48 |
Correct |
79 ms |
1756 KB |
Output is correct |
49 |
Correct |
65 ms |
1656 KB |
Output is correct |
50 |
Correct |
50 ms |
1144 KB |
Output is correct |
51 |
Correct |
23 ms |
760 KB |
Output is correct |
52 |
Correct |
112 ms |
2044 KB |
Output is correct |
53 |
Correct |
82 ms |
1528 KB |
Output is correct |
54 |
Correct |
117 ms |
1656 KB |
Output is correct |
55 |
Correct |
235 ms |
2936 KB |
Output is correct |
56 |
Correct |
103 ms |
1784 KB |
Output is correct |
57 |
Correct |
250 ms |
3124 KB |
Output is correct |
58 |
Correct |
124 ms |
1840 KB |
Output is correct |
59 |
Correct |
170 ms |
2136 KB |
Output is correct |
60 |
Correct |
61 ms |
1144 KB |
Output is correct |
61 |
Correct |
192 ms |
2424 KB |
Output is correct |
62 |
Correct |
200 ms |
2652 KB |
Output is correct |
63 |
Correct |
209 ms |
2808 KB |
Output is correct |
64 |
Correct |
206 ms |
2772 KB |
Output is correct |
65 |
Correct |
57 ms |
1372 KB |
Output is correct |
66 |
Correct |
65 ms |
1528 KB |
Output is correct |
67 |
Correct |
183 ms |
2232 KB |
Output is correct |
68 |
Correct |
101 ms |
1912 KB |
Output is correct |
69 |
Correct |
666 ms |
5500 KB |
Output is correct |
70 |
Correct |
394 ms |
3436 KB |
Output is correct |
71 |
Correct |
351 ms |
3336 KB |
Output is correct |
72 |
Correct |
346 ms |
2936 KB |
Output is correct |
73 |
Correct |
347 ms |
2936 KB |
Output is correct |
74 |
Correct |
722 ms |
5728 KB |
Output is correct |
75 |
Correct |
548 ms |
4504 KB |
Output is correct |
76 |
Correct |
690 ms |
6264 KB |
Output is correct |
77 |
Correct |
753 ms |
5944 KB |
Output is correct |