# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1117610 | NguyenPhucThang | Bank (IZhO14_bank) | C++14 | 1080 ms | 5588 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;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vii;
typedef pair<int, pair<int, int>> piii;
#define forr(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define forf(i, a, b) for (int i = (a); i < (b); i++)
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(), v.end()
#define mask(i) (1LL << (i))
#define bit(x, i) (((x) >> (i)) & 1)
#define bp __builtin_popcountll
#define file "test"
template<class X, class Y>
bool minz(X &x, const Y &y) {
if (x > y) {
x = y;
return true;
} return false;
}
template<class X, class Y>
bool maxz(X &x, const Y &y) {
if (x < y) {
x = y;
return true;
} return false;
}
const int base = 31;
const ll mod = 1e9 + 7; // 998244353;
const ll oo = (ll) 1e16;
const int N = 2e5 + 5;
vi mask_list[N];
bool dp[25][(1 << 20)];
int a[N], b[N];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
#endif // ONLINE_JUDGE
int n, m;
cin >> n >> m;
forr(i, 1, n) cin >> a[i];
forr(i, 1, m) cin >> b[i];
forr(mask, 0, (1 << m) - 1) {
int sum = 0;
forr(i, 1, m) if (bit(mask, i - 1)) sum += b[i];
mask_list[sum].pb(mask);
}
dp[0][0] = true;
forr(i, 1, n) {
forr(mask, 0, (1 << m) - 1) {
for(int mask2 : mask_list[a[i]]) {
if ((mask | mask2) == mask)
dp[i][mask] |= dp[i - 1][mask ^ mask2];
}
}
}
bool res = false;
forr(mask, 0, (1 << m) - 1) res |= dp[n][mask];
cout << (res ? "YES" : "NO");
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... |