//Bismillahi-rahmani-rahim
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef map <int, int> mii;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const int inf=1e9;
#define azdar priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>
#define Lebap ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
#define pf push_front
#define pk pop_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
//#include <conio.h>
#include <climits>
const int N = 500*500;
int dp[N+509], dp1[N+509],n,a[509], sum;
int san[N];
int main(){
Lebap;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i], sum += a[i];
dp[0]=1;
for(int i=1;i<=n;i++){
for(int j=N;j>=0;j--){
if(dp[j]) dp[j+a[i]]+=dp[j];
}
}
if(sum%2 || dp[sum/2]==0) return cout << 0 , 0;
for(int i=1;i<=n;i++){
memset( dp1 , 0, sizeof(dp1) );
for(int j=0;j<=N;j++){
dp1[j] += dp[j];
dp1[j+a[i]] -= dp1[j];
}
for(int j=0;j<=N;j++){
if( (sum-a[i]+j)%2==0 && sum-a[i]-j>=0 && dp1[ (sum-a[i]-j)/2 ]!=0 ) san[j]++;
}
}
vector <int> ans;
for(int i=1;i<=N;i++ ) if(san[i]==n) ans.pb(i);
cout << ans.size() << endl;
for(int i=0;i<ans.size();i++) cout << ans[i] << " ";
return 0;
}
Compilation message
bootfall.cpp: In function 'int main()':
bootfall.cpp:55:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<ans.size();i++) cout << ans[i] << " ";
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
5112 KB |
Output is correct |
2 |
Correct |
9 ms |
5112 KB |
Output is correct |
3 |
Correct |
0 ms |
5112 KB |
Output is correct |
4 |
Correct |
9 ms |
5112 KB |
Output is correct |
5 |
Correct |
23 ms |
5112 KB |
Output is correct |
6 |
Correct |
16 ms |
5112 KB |
Output is correct |
7 |
Correct |
9 ms |
5112 KB |
Output is correct |
8 |
Correct |
19 ms |
5112 KB |
Output is correct |
9 |
Correct |
6 ms |
5112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
5112 KB |
Output is correct |
2 |
Correct |
9 ms |
5112 KB |
Output is correct |
3 |
Correct |
0 ms |
5112 KB |
Output is correct |
4 |
Correct |
9 ms |
5112 KB |
Output is correct |
5 |
Correct |
23 ms |
5112 KB |
Output is correct |
6 |
Correct |
16 ms |
5112 KB |
Output is correct |
7 |
Correct |
9 ms |
5112 KB |
Output is correct |
8 |
Correct |
19 ms |
5112 KB |
Output is correct |
9 |
Correct |
6 ms |
5112 KB |
Output is correct |
10 |
Correct |
43 ms |
5112 KB |
Output is correct |
11 |
Correct |
46 ms |
5112 KB |
Output is correct |
12 |
Correct |
69 ms |
5112 KB |
Output is correct |
13 |
Correct |
39 ms |
5112 KB |
Output is correct |
14 |
Correct |
43 ms |
5112 KB |
Output is correct |
15 |
Correct |
43 ms |
5112 KB |
Output is correct |
16 |
Correct |
39 ms |
5112 KB |
Output is correct |
17 |
Correct |
26 ms |
5112 KB |
Output is correct |
18 |
Correct |
36 ms |
5112 KB |
Output is correct |
19 |
Correct |
39 ms |
5112 KB |
Output is correct |
20 |
Correct |
33 ms |
5112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
5112 KB |
Output is correct |
2 |
Correct |
9 ms |
5112 KB |
Output is correct |
3 |
Correct |
0 ms |
5112 KB |
Output is correct |
4 |
Correct |
9 ms |
5112 KB |
Output is correct |
5 |
Correct |
23 ms |
5112 KB |
Output is correct |
6 |
Correct |
16 ms |
5112 KB |
Output is correct |
7 |
Correct |
9 ms |
5112 KB |
Output is correct |
8 |
Correct |
19 ms |
5112 KB |
Output is correct |
9 |
Correct |
6 ms |
5112 KB |
Output is correct |
10 |
Correct |
43 ms |
5112 KB |
Output is correct |
11 |
Correct |
46 ms |
5112 KB |
Output is correct |
12 |
Correct |
69 ms |
5112 KB |
Output is correct |
13 |
Correct |
39 ms |
5112 KB |
Output is correct |
14 |
Correct |
43 ms |
5112 KB |
Output is correct |
15 |
Correct |
43 ms |
5112 KB |
Output is correct |
16 |
Correct |
39 ms |
5112 KB |
Output is correct |
17 |
Correct |
26 ms |
5112 KB |
Output is correct |
18 |
Correct |
36 ms |
5112 KB |
Output is correct |
19 |
Correct |
39 ms |
5112 KB |
Output is correct |
20 |
Correct |
33 ms |
5112 KB |
Output is correct |
21 |
Correct |
86 ms |
5112 KB |
Output is correct |
22 |
Correct |
86 ms |
5112 KB |
Output is correct |
23 |
Correct |
76 ms |
5112 KB |
Output is correct |
24 |
Runtime error |
159 ms |
5112 KB |
Execution killed because of forbidden syscall writev (20) |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
5112 KB |
Output is correct |
2 |
Correct |
9 ms |
5112 KB |
Output is correct |
3 |
Correct |
0 ms |
5112 KB |
Output is correct |
4 |
Correct |
9 ms |
5112 KB |
Output is correct |
5 |
Correct |
23 ms |
5112 KB |
Output is correct |
6 |
Correct |
16 ms |
5112 KB |
Output is correct |
7 |
Correct |
9 ms |
5112 KB |
Output is correct |
8 |
Correct |
19 ms |
5112 KB |
Output is correct |
9 |
Correct |
6 ms |
5112 KB |
Output is correct |
10 |
Correct |
43 ms |
5112 KB |
Output is correct |
11 |
Correct |
46 ms |
5112 KB |
Output is correct |
12 |
Correct |
69 ms |
5112 KB |
Output is correct |
13 |
Correct |
39 ms |
5112 KB |
Output is correct |
14 |
Correct |
43 ms |
5112 KB |
Output is correct |
15 |
Correct |
43 ms |
5112 KB |
Output is correct |
16 |
Correct |
39 ms |
5112 KB |
Output is correct |
17 |
Correct |
26 ms |
5112 KB |
Output is correct |
18 |
Correct |
36 ms |
5112 KB |
Output is correct |
19 |
Correct |
39 ms |
5112 KB |
Output is correct |
20 |
Correct |
33 ms |
5112 KB |
Output is correct |
21 |
Correct |
86 ms |
5112 KB |
Output is correct |
22 |
Correct |
86 ms |
5112 KB |
Output is correct |
23 |
Correct |
76 ms |
5112 KB |
Output is correct |
24 |
Runtime error |
159 ms |
5112 KB |
Execution killed because of forbidden syscall writev (20) |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
5112 KB |
Output is correct |
2 |
Correct |
9 ms |
5112 KB |
Output is correct |
3 |
Correct |
0 ms |
5112 KB |
Output is correct |
4 |
Correct |
9 ms |
5112 KB |
Output is correct |
5 |
Correct |
23 ms |
5112 KB |
Output is correct |
6 |
Correct |
16 ms |
5112 KB |
Output is correct |
7 |
Correct |
9 ms |
5112 KB |
Output is correct |
8 |
Correct |
19 ms |
5112 KB |
Output is correct |
9 |
Correct |
6 ms |
5112 KB |
Output is correct |
10 |
Correct |
43 ms |
5112 KB |
Output is correct |
11 |
Correct |
46 ms |
5112 KB |
Output is correct |
12 |
Correct |
69 ms |
5112 KB |
Output is correct |
13 |
Correct |
39 ms |
5112 KB |
Output is correct |
14 |
Correct |
43 ms |
5112 KB |
Output is correct |
15 |
Correct |
43 ms |
5112 KB |
Output is correct |
16 |
Correct |
39 ms |
5112 KB |
Output is correct |
17 |
Correct |
26 ms |
5112 KB |
Output is correct |
18 |
Correct |
36 ms |
5112 KB |
Output is correct |
19 |
Correct |
39 ms |
5112 KB |
Output is correct |
20 |
Correct |
33 ms |
5112 KB |
Output is correct |
21 |
Correct |
86 ms |
5112 KB |
Output is correct |
22 |
Correct |
86 ms |
5112 KB |
Output is correct |
23 |
Correct |
76 ms |
5112 KB |
Output is correct |
24 |
Runtime error |
159 ms |
5112 KB |
Execution killed because of forbidden syscall writev (20) |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
5112 KB |
Output is correct |
2 |
Correct |
9 ms |
5112 KB |
Output is correct |
3 |
Correct |
0 ms |
5112 KB |
Output is correct |
4 |
Correct |
9 ms |
5112 KB |
Output is correct |
5 |
Correct |
23 ms |
5112 KB |
Output is correct |
6 |
Correct |
16 ms |
5112 KB |
Output is correct |
7 |
Correct |
9 ms |
5112 KB |
Output is correct |
8 |
Correct |
19 ms |
5112 KB |
Output is correct |
9 |
Correct |
6 ms |
5112 KB |
Output is correct |
10 |
Correct |
43 ms |
5112 KB |
Output is correct |
11 |
Correct |
46 ms |
5112 KB |
Output is correct |
12 |
Correct |
69 ms |
5112 KB |
Output is correct |
13 |
Correct |
39 ms |
5112 KB |
Output is correct |
14 |
Correct |
43 ms |
5112 KB |
Output is correct |
15 |
Correct |
43 ms |
5112 KB |
Output is correct |
16 |
Correct |
39 ms |
5112 KB |
Output is correct |
17 |
Correct |
26 ms |
5112 KB |
Output is correct |
18 |
Correct |
36 ms |
5112 KB |
Output is correct |
19 |
Correct |
39 ms |
5112 KB |
Output is correct |
20 |
Correct |
33 ms |
5112 KB |
Output is correct |
21 |
Correct |
86 ms |
5112 KB |
Output is correct |
22 |
Correct |
86 ms |
5112 KB |
Output is correct |
23 |
Correct |
76 ms |
5112 KB |
Output is correct |
24 |
Runtime error |
159 ms |
5112 KB |
Execution killed because of forbidden syscall writev (20) |
25 |
Halted |
0 ms |
0 KB |
- |