#include <bits/stdc++.h>
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
#define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
#define per(i,r,l) for(int i = (r); i >= (l); i--)
#define rep(i,l,r) for(int i = (l); i < (r); i++)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ss second
#define ff first
void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 5e2+5, lg = 20, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}
bool dp[maxn][maxn*maxn];
int main(){
cin.tie(0) -> sync_with_stdio(0);
int n; cin >> n;
vector<int> a(n);
int sum = 0;
rep(i,0,n) cin >> a[i], sum += a[i];
rep(k,0,n+1){
dp[k][0] = true;
rep(i,0,n){
if(i == k) continue;
per(j,sum,a[i]) dp[k][j] |= dp[k][j-a[i]];
}
}
if((sum&1) || !dp[n][sum>>1]) return cout << "0\n", 0;
rep(i,0,n) if(a[i]%2 != a[0]%2) return cout << "0\n", 0;
vector<int> ans;
rep(i,1,sum+1) if(i%2 == a[0]%2){
bool ok = true;
rep(j,0,n){
int t = (sum - a[j] + i)>>1;
if(t > sum || !dp[j][t]) {
ok = false;
break;
}
}
if(ok) ans.pb(i);
}
cout << sz(ans) << '\n';
for(int c: ans) cout << c << ' ';
if(sz(ans)) cout << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
472 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
472 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
10 ms |
844 KB |
Output is correct |
22 |
Correct |
14 ms |
852 KB |
Output is correct |
23 |
Correct |
4 ms |
596 KB |
Output is correct |
24 |
Correct |
22 ms |
1108 KB |
Output is correct |
25 |
Correct |
44 ms |
1612 KB |
Output is correct |
26 |
Correct |
59 ms |
1672 KB |
Output is correct |
27 |
Correct |
43 ms |
1552 KB |
Output is correct |
28 |
Correct |
46 ms |
1656 KB |
Output is correct |
29 |
Correct |
45 ms |
1612 KB |
Output is correct |
30 |
Correct |
26 ms |
1200 KB |
Output is correct |
31 |
Correct |
37 ms |
1544 KB |
Output is correct |
32 |
Correct |
23 ms |
1264 KB |
Output is correct |
33 |
Correct |
57 ms |
1692 KB |
Output is correct |
34 |
Correct |
50 ms |
1660 KB |
Output is correct |
35 |
Correct |
47 ms |
1612 KB |
Output is correct |
36 |
Correct |
26 ms |
1212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
472 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
10 ms |
844 KB |
Output is correct |
22 |
Correct |
14 ms |
852 KB |
Output is correct |
23 |
Correct |
4 ms |
596 KB |
Output is correct |
24 |
Correct |
22 ms |
1108 KB |
Output is correct |
25 |
Correct |
44 ms |
1612 KB |
Output is correct |
26 |
Correct |
59 ms |
1672 KB |
Output is correct |
27 |
Correct |
43 ms |
1552 KB |
Output is correct |
28 |
Correct |
46 ms |
1656 KB |
Output is correct |
29 |
Correct |
45 ms |
1612 KB |
Output is correct |
30 |
Correct |
26 ms |
1200 KB |
Output is correct |
31 |
Correct |
37 ms |
1544 KB |
Output is correct |
32 |
Correct |
23 ms |
1264 KB |
Output is correct |
33 |
Correct |
57 ms |
1692 KB |
Output is correct |
34 |
Correct |
50 ms |
1660 KB |
Output is correct |
35 |
Correct |
47 ms |
1612 KB |
Output is correct |
36 |
Correct |
26 ms |
1212 KB |
Output is correct |
37 |
Correct |
395 ms |
5156 KB |
Output is correct |
38 |
Correct |
452 ms |
5216 KB |
Output is correct |
39 |
Execution timed out |
1098 ms |
9732 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
472 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
10 ms |
844 KB |
Output is correct |
22 |
Correct |
14 ms |
852 KB |
Output is correct |
23 |
Correct |
4 ms |
596 KB |
Output is correct |
24 |
Correct |
22 ms |
1108 KB |
Output is correct |
25 |
Correct |
44 ms |
1612 KB |
Output is correct |
26 |
Correct |
59 ms |
1672 KB |
Output is correct |
27 |
Correct |
43 ms |
1552 KB |
Output is correct |
28 |
Correct |
46 ms |
1656 KB |
Output is correct |
29 |
Correct |
45 ms |
1612 KB |
Output is correct |
30 |
Correct |
26 ms |
1200 KB |
Output is correct |
31 |
Correct |
37 ms |
1544 KB |
Output is correct |
32 |
Correct |
23 ms |
1264 KB |
Output is correct |
33 |
Correct |
57 ms |
1692 KB |
Output is correct |
34 |
Correct |
50 ms |
1660 KB |
Output is correct |
35 |
Correct |
47 ms |
1612 KB |
Output is correct |
36 |
Correct |
26 ms |
1212 KB |
Output is correct |
37 |
Correct |
395 ms |
5156 KB |
Output is correct |
38 |
Correct |
452 ms |
5216 KB |
Output is correct |
39 |
Execution timed out |
1098 ms |
9732 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
472 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
10 ms |
844 KB |
Output is correct |
22 |
Correct |
14 ms |
852 KB |
Output is correct |
23 |
Correct |
4 ms |
596 KB |
Output is correct |
24 |
Correct |
22 ms |
1108 KB |
Output is correct |
25 |
Correct |
44 ms |
1612 KB |
Output is correct |
26 |
Correct |
59 ms |
1672 KB |
Output is correct |
27 |
Correct |
43 ms |
1552 KB |
Output is correct |
28 |
Correct |
46 ms |
1656 KB |
Output is correct |
29 |
Correct |
45 ms |
1612 KB |
Output is correct |
30 |
Correct |
26 ms |
1200 KB |
Output is correct |
31 |
Correct |
37 ms |
1544 KB |
Output is correct |
32 |
Correct |
23 ms |
1264 KB |
Output is correct |
33 |
Correct |
57 ms |
1692 KB |
Output is correct |
34 |
Correct |
50 ms |
1660 KB |
Output is correct |
35 |
Correct |
47 ms |
1612 KB |
Output is correct |
36 |
Correct |
26 ms |
1212 KB |
Output is correct |
37 |
Correct |
395 ms |
5156 KB |
Output is correct |
38 |
Correct |
452 ms |
5216 KB |
Output is correct |
39 |
Execution timed out |
1098 ms |
9732 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |