#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 500;
const int ofs = N*N;
const int MOD = 1000000007;
int add(int a, int b){ a += b; if(a >= MOD) a -= MOD; return a; }
int sub(int a, int b){ return add(a, MOD - b); }
int moze[N*N+5];
int dp[2*N*N+5];
int a[N+5];
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int n;
cin >> n;
int poc = 0;
for(int i=1; i<=n; i++){
cin >> a[i];
poc -= a[i];
a[i] *= 2;
}
dp[ofs + poc] = 1;
for(int i=1; i<=n; i++){
for(int j=N*N; j>=-N*N+a[i]; j--){
dp[ofs + j] = add(dp[ofs + j], dp[ofs + j - a[i]]);
}
}
for(int i=1; i<=n; i++){
for(int j=-N*N+a[i]; j<=N*N; j++){
dp[ofs + j] = sub(dp[ofs + j], dp[ofs + j - a[i]]);
}
for(int j=1; j<=N*N; j++) moze[j] += (dp[ofs + j - a[i]/2] > 0);
for(int j=N*N; j>=-N*N+a[i]; j--){
dp[ofs + j] = add(dp[ofs + j], dp[ofs + j - a[i]]);
}
}
vector <int> vec;
for(int i=1; i<=N*N; i++) if(moze[i] == n) vec.push_back(i);
cout << vec.size() << "\n";
for(auto c : vec) cout << c << " ";
cout << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
3252 KB |
Output is correct |
2 |
Correct |
14 ms |
3252 KB |
Output is correct |
3 |
Incorrect |
9 ms |
3200 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
3252 KB |
Output is correct |
2 |
Correct |
14 ms |
3252 KB |
Output is correct |
3 |
Incorrect |
9 ms |
3200 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
3252 KB |
Output is correct |
2 |
Correct |
14 ms |
3252 KB |
Output is correct |
3 |
Incorrect |
9 ms |
3200 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
3252 KB |
Output is correct |
2 |
Correct |
14 ms |
3252 KB |
Output is correct |
3 |
Incorrect |
9 ms |
3200 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
3252 KB |
Output is correct |
2 |
Correct |
14 ms |
3252 KB |
Output is correct |
3 |
Incorrect |
9 ms |
3200 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
3252 KB |
Output is correct |
2 |
Correct |
14 ms |
3252 KB |
Output is correct |
3 |
Incorrect |
9 ms |
3200 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |