# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
17893 | chrome | Bank (IZhO14_bank) | C++98 | 1066 ms | 6980 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>
using namespace std;
#define ll long long
#define foreach(it, S) for (__typeof (S.begin()) it = S.begin(); it != S.end(); it++)
#define all(x) x.begin(), x.end()
#define endl '\n'
#define _ ios_base :: sync_with_stdio(false); cin.tie(NULL);
#ifdef inputf
#define fname ""
#else
#define fname "" // <- Here
#endif
const double eps = 1e-9;
const int MaxN = int(2e5) + 256;
const int MOD = int(1e9) + 7;
template <typename T> inline T gcd(T a, T b) {
return b ? gcd (b, a % b) : a;
}
inline bool Palindrome(const string& s) {
return equal(s.begin(), s.end(), s.rbegin());
}
int n, m;
int a[50], b[50];
bool calced[20][1 << 20];
bool d[20][1 << 20];
bool f(int i, int msk) {
if (i == n)
return true;
if (calced[i][msk])
return d[i][msk];
calced[i][msk] = true;
bool res = false;
for (int nxt = msk; nxt > 0; nxt = (nxt - 1) & msk) {
int nxtmsk = nxt ^ msk;
int cur = 0;
for (int i = 0; i < m; ++i)
if (nxt >> i & 1)
cur += b[i];
if (cur == a[i]) {
if (f(i + 1, nxtmsk)) {
res = true; break;
}
}
}
return d[i][msk] = res;
}
int main() { // _
#ifdef lcl
freopen(fname".in", "r", stdin);
freopen(fname".out", "w", stdout);
#endif
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i)
scanf("%d", a + i);
for (int i = 0; i < m; ++i)
scanf("%d", b + i);
puts(vector<string>{"NO", "YES"}[f(0, (1 << m) - 1)].c_str());
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... |