#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];
bool canruk(int lack)
{
memset(dp, 0, sizeof(dp));
int mxval = 0;
dp[0] = 1;
int sm = 0;
for(int i = 1; i <= n; ++i)
if(i != lack)
sm += v[i];
for(int i = 1; i <= n; ++i)
{
if(i == lack)
continue;
for(int j = mxval; j >= 0; --j)
if(dp[j])
dp[j + v[i]] = 1;
mxval += v[i];
mxval = min(mxval, sm / 2);
}
if(lack == 0)
{
if(sm % 2 == 0 && dp[sm / 2])
return 1;
return 0;
}
else
{
for(int i = 0; i <= sm/2; ++i)
if(dp[i])
frq[sm - 2 * i]++;
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 |
632 KB |
Output is correct |
2 |
Correct |
4 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
632 KB |
Output is correct |
4 |
Correct |
4 ms |
632 KB |
Output is correct |
5 |
Correct |
5 ms |
604 KB |
Output is correct |
6 |
Correct |
4 ms |
632 KB |
Output is correct |
7 |
Correct |
4 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
632 KB |
Output is correct |
9 |
Correct |
5 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
632 KB |
Output is correct |
2 |
Correct |
4 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
632 KB |
Output is correct |
4 |
Correct |
4 ms |
632 KB |
Output is correct |
5 |
Correct |
5 ms |
604 KB |
Output is correct |
6 |
Correct |
4 ms |
632 KB |
Output is correct |
7 |
Correct |
4 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
632 KB |
Output is correct |
9 |
Correct |
5 ms |
632 KB |
Output is correct |
10 |
Correct |
5 ms |
636 KB |
Output is correct |
11 |
Correct |
5 ms |
632 KB |
Output is correct |
12 |
Correct |
5 ms |
632 KB |
Output is correct |
13 |
Correct |
5 ms |
632 KB |
Output is correct |
14 |
Correct |
5 ms |
632 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
632 KB |
Output is correct |
17 |
Correct |
5 ms |
632 KB |
Output is correct |
18 |
Correct |
5 ms |
632 KB |
Output is correct |
19 |
Correct |
5 ms |
632 KB |
Output is correct |
20 |
Correct |
5 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
632 KB |
Output is correct |
2 |
Correct |
4 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
632 KB |
Output is correct |
4 |
Correct |
4 ms |
632 KB |
Output is correct |
5 |
Correct |
5 ms |
604 KB |
Output is correct |
6 |
Correct |
4 ms |
632 KB |
Output is correct |
7 |
Correct |
4 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
632 KB |
Output is correct |
9 |
Correct |
5 ms |
632 KB |
Output is correct |
10 |
Correct |
5 ms |
636 KB |
Output is correct |
11 |
Correct |
5 ms |
632 KB |
Output is correct |
12 |
Correct |
5 ms |
632 KB |
Output is correct |
13 |
Correct |
5 ms |
632 KB |
Output is correct |
14 |
Correct |
5 ms |
632 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
632 KB |
Output is correct |
17 |
Correct |
5 ms |
632 KB |
Output is correct |
18 |
Correct |
5 ms |
632 KB |
Output is correct |
19 |
Correct |
5 ms |
632 KB |
Output is correct |
20 |
Correct |
5 ms |
632 KB |
Output is correct |
21 |
Correct |
9 ms |
632 KB |
Output is correct |
22 |
Correct |
11 ms |
632 KB |
Output is correct |
23 |
Correct |
7 ms |
680 KB |
Output is correct |
24 |
Correct |
18 ms |
632 KB |
Output is correct |
25 |
Correct |
51 ms |
668 KB |
Output is correct |
26 |
Correct |
60 ms |
632 KB |
Output is correct |
27 |
Correct |
44 ms |
632 KB |
Output is correct |
28 |
Correct |
49 ms |
632 KB |
Output is correct |
29 |
Correct |
55 ms |
632 KB |
Output is correct |
30 |
Correct |
22 ms |
632 KB |
Output is correct |
31 |
Correct |
39 ms |
632 KB |
Output is correct |
32 |
Correct |
20 ms |
660 KB |
Output is correct |
33 |
Correct |
45 ms |
632 KB |
Output is correct |
34 |
Correct |
45 ms |
632 KB |
Output is correct |
35 |
Correct |
54 ms |
712 KB |
Output is correct |
36 |
Correct |
19 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
632 KB |
Output is correct |
2 |
Correct |
4 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
632 KB |
Output is correct |
4 |
Correct |
4 ms |
632 KB |
Output is correct |
5 |
Correct |
5 ms |
604 KB |
Output is correct |
6 |
Correct |
4 ms |
632 KB |
Output is correct |
7 |
Correct |
4 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
632 KB |
Output is correct |
9 |
Correct |
5 ms |
632 KB |
Output is correct |
10 |
Correct |
5 ms |
636 KB |
Output is correct |
11 |
Correct |
5 ms |
632 KB |
Output is correct |
12 |
Correct |
5 ms |
632 KB |
Output is correct |
13 |
Correct |
5 ms |
632 KB |
Output is correct |
14 |
Correct |
5 ms |
632 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
632 KB |
Output is correct |
17 |
Correct |
5 ms |
632 KB |
Output is correct |
18 |
Correct |
5 ms |
632 KB |
Output is correct |
19 |
Correct |
5 ms |
632 KB |
Output is correct |
20 |
Correct |
5 ms |
632 KB |
Output is correct |
21 |
Correct |
9 ms |
632 KB |
Output is correct |
22 |
Correct |
11 ms |
632 KB |
Output is correct |
23 |
Correct |
7 ms |
680 KB |
Output is correct |
24 |
Correct |
18 ms |
632 KB |
Output is correct |
25 |
Correct |
51 ms |
668 KB |
Output is correct |
26 |
Correct |
60 ms |
632 KB |
Output is correct |
27 |
Correct |
44 ms |
632 KB |
Output is correct |
28 |
Correct |
49 ms |
632 KB |
Output is correct |
29 |
Correct |
55 ms |
632 KB |
Output is correct |
30 |
Correct |
22 ms |
632 KB |
Output is correct |
31 |
Correct |
39 ms |
632 KB |
Output is correct |
32 |
Correct |
20 ms |
660 KB |
Output is correct |
33 |
Correct |
45 ms |
632 KB |
Output is correct |
34 |
Correct |
45 ms |
632 KB |
Output is correct |
35 |
Correct |
54 ms |
712 KB |
Output is correct |
36 |
Correct |
19 ms |
632 KB |
Output is correct |
37 |
Correct |
306 ms |
760 KB |
Output is correct |
38 |
Correct |
309 ms |
760 KB |
Output is correct |
39 |
Execution timed out |
1073 ms |
760 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
632 KB |
Output is correct |
2 |
Correct |
4 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
632 KB |
Output is correct |
4 |
Correct |
4 ms |
632 KB |
Output is correct |
5 |
Correct |
5 ms |
604 KB |
Output is correct |
6 |
Correct |
4 ms |
632 KB |
Output is correct |
7 |
Correct |
4 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
632 KB |
Output is correct |
9 |
Correct |
5 ms |
632 KB |
Output is correct |
10 |
Correct |
5 ms |
636 KB |
Output is correct |
11 |
Correct |
5 ms |
632 KB |
Output is correct |
12 |
Correct |
5 ms |
632 KB |
Output is correct |
13 |
Correct |
5 ms |
632 KB |
Output is correct |
14 |
Correct |
5 ms |
632 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
632 KB |
Output is correct |
17 |
Correct |
5 ms |
632 KB |
Output is correct |
18 |
Correct |
5 ms |
632 KB |
Output is correct |
19 |
Correct |
5 ms |
632 KB |
Output is correct |
20 |
Correct |
5 ms |
632 KB |
Output is correct |
21 |
Correct |
9 ms |
632 KB |
Output is correct |
22 |
Correct |
11 ms |
632 KB |
Output is correct |
23 |
Correct |
7 ms |
680 KB |
Output is correct |
24 |
Correct |
18 ms |
632 KB |
Output is correct |
25 |
Correct |
51 ms |
668 KB |
Output is correct |
26 |
Correct |
60 ms |
632 KB |
Output is correct |
27 |
Correct |
44 ms |
632 KB |
Output is correct |
28 |
Correct |
49 ms |
632 KB |
Output is correct |
29 |
Correct |
55 ms |
632 KB |
Output is correct |
30 |
Correct |
22 ms |
632 KB |
Output is correct |
31 |
Correct |
39 ms |
632 KB |
Output is correct |
32 |
Correct |
20 ms |
660 KB |
Output is correct |
33 |
Correct |
45 ms |
632 KB |
Output is correct |
34 |
Correct |
45 ms |
632 KB |
Output is correct |
35 |
Correct |
54 ms |
712 KB |
Output is correct |
36 |
Correct |
19 ms |
632 KB |
Output is correct |
37 |
Correct |
306 ms |
760 KB |
Output is correct |
38 |
Correct |
309 ms |
760 KB |
Output is correct |
39 |
Execution timed out |
1073 ms |
760 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
632 KB |
Output is correct |
2 |
Correct |
4 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
632 KB |
Output is correct |
4 |
Correct |
4 ms |
632 KB |
Output is correct |
5 |
Correct |
5 ms |
604 KB |
Output is correct |
6 |
Correct |
4 ms |
632 KB |
Output is correct |
7 |
Correct |
4 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
632 KB |
Output is correct |
9 |
Correct |
5 ms |
632 KB |
Output is correct |
10 |
Correct |
5 ms |
636 KB |
Output is correct |
11 |
Correct |
5 ms |
632 KB |
Output is correct |
12 |
Correct |
5 ms |
632 KB |
Output is correct |
13 |
Correct |
5 ms |
632 KB |
Output is correct |
14 |
Correct |
5 ms |
632 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
632 KB |
Output is correct |
17 |
Correct |
5 ms |
632 KB |
Output is correct |
18 |
Correct |
5 ms |
632 KB |
Output is correct |
19 |
Correct |
5 ms |
632 KB |
Output is correct |
20 |
Correct |
5 ms |
632 KB |
Output is correct |
21 |
Correct |
9 ms |
632 KB |
Output is correct |
22 |
Correct |
11 ms |
632 KB |
Output is correct |
23 |
Correct |
7 ms |
680 KB |
Output is correct |
24 |
Correct |
18 ms |
632 KB |
Output is correct |
25 |
Correct |
51 ms |
668 KB |
Output is correct |
26 |
Correct |
60 ms |
632 KB |
Output is correct |
27 |
Correct |
44 ms |
632 KB |
Output is correct |
28 |
Correct |
49 ms |
632 KB |
Output is correct |
29 |
Correct |
55 ms |
632 KB |
Output is correct |
30 |
Correct |
22 ms |
632 KB |
Output is correct |
31 |
Correct |
39 ms |
632 KB |
Output is correct |
32 |
Correct |
20 ms |
660 KB |
Output is correct |
33 |
Correct |
45 ms |
632 KB |
Output is correct |
34 |
Correct |
45 ms |
632 KB |
Output is correct |
35 |
Correct |
54 ms |
712 KB |
Output is correct |
36 |
Correct |
19 ms |
632 KB |
Output is correct |
37 |
Correct |
306 ms |
760 KB |
Output is correct |
38 |
Correct |
309 ms |
760 KB |
Output is correct |
39 |
Execution timed out |
1073 ms |
760 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |