#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 ddp[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=poc; j>=-poc+a[i]; j--){
dp[ofs + j] = add(dp[ofs + j], dp[ofs + j - a[i]]);
}
}
if(dp[ofs] == 0){
cout << "0\n";
return 0;
}
for(int i=1; i<=n; i++){
for(int j=-poc+a[i]; j<=poc; j++) ddp[ofs + j] = sub(dp[ofs + j], ddp[ofs + j - a[i]]);
for(int j=1; j<=poc; j++) moze[j] += (ddp[ofs + j - a[i]/2] > 0);
}
vector <int> vec;
for(int i=1; i<=poc; i++) if(moze[i] == n) vec.push_back(i);
cout << vec.size() << "\n";
for(auto c : vec) cout << c << " ";
cout << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |