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 <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define mp make_pair
const int N = 502;
int n;
int a[N];
bool dp[N][N * N];
int main() {
cin >> n;
int sum = 0;
bool isev = 0, isod = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum += a[i];
if (a[i] % 2 == 0)
isev = 1;
else
isod = 1;
}
if ((isev && isod) || (sum % 2 == 1)) {
cout << 0 << endl;
return 0;
}
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < a[i]; j++) {
dp[i][j] = dp[i - 1][j];
}
for (int j = a[i]; j <= sum; j++) {
dp[i][j] = dp[i - 1][j] || dp[i - 1][j - a[i]];
}
}
if (dp[n][sum / 2] == 0) {
cout << 0 << endl;
return 0;
}
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... |