This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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; j<=poc; j++){
ddp[ofs + j] = dp[ofs + j];
if(ofs + j - a[i] >= 0) ddp[ofs + j] = sub(ddp[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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |