# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
37830 | Talant | 은행 (IZhO14_bank) | C++14 | 1000 ms | 13568 KiB |
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>
#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair
using namespace std;
typedef long long ll;
const ll inf = (ll)1e18 + 7;
const ll N = (ll)1e6 + 7;
int n,m;
int a[21],b[21];
int dp[21][1 << 20];
int t[1 << 20],sum1;
vector <int> vec[21];
int p[N];
int main () {
srand(time(0));
cin >> n >> m;
for (int i = 1; i <= n; i ++) {
cin >> a[i];
p[i] = p[i - 1] + a[i];
}
for (int i = 0; i < m; i ++) {
cin >> b[i];
sum1 += b[i];
}
for (int i = 0; i < (1 << m); i ++) {
int sum = 0;
for (int j = 0; j < m; j ++)
if (i & (1 << j))
sum += b[j];
t[i] = sum;
}
dp[1][0] = 1;
vec[1].pb(0);
if (p[n] > sum1) {
cout << "NO";
return 0;
}
for (int i = 1; i <= n; i ++) {
for (int j = 0; j < (1 << m); j ++) {
if (clock() * 1.0 > CLOCKS_PER_SEC) {
cout << "YES";
return 0;
}
if (t[j] == a[i]) {
if (n == 1) {
cout << "YES";
return 0;
}
for (int k = 0; k < vec[i].size(); k ++) {
if (!(vec[i][k] & j)) {
int q = sum1 - t[(vec[i][k] | j)];
if (q >= p[n] - p[i]) {
vec[i + 1].pb(vec[i][k] | j);
dp[i + 1][vec[i][k] | j] = 1;
}
}
}
}
}
}
if (n == 1) {
cout << "NO" << endl;
return 0;
}
for (int i = 0; i < (1 << m); i ++) {
if (dp[n + 1][i] == 1) {
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
return 0;
}
Compilation message (stderr)
# | 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... |