# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|
640541 | | ymm | 은행 (IZhO14_bank) | C++17 | | 1084 ms | 6456 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 Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
const int N = 20;
bool dp[2][1<<N];
int a[N], b[N];
int sum[1<<N];
int n, m;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("abm,bmi,bmi2")
int main()
{
cin.tie(0) -> sync_with_stdio(false);
cin >> n >> m;
int kooft = 0;
Loop (i,0,n) {
cin >> a[i];
kooft -= a[i];
}
Loop (i,0,m) {
cin >> b[i];
kooft += b[i];
}
if (kooft < 0) {
cout << "NO" << '\n';
return 0;
}
sort(a, a+n);
sort(b, b+m);
reverse(b, b+m);
memset(dp[0], 1, sizeof(dp[0]));
Loop (i,1,1<<m)
sum[i] = sum[i ^ (i & -i)] + b[__builtin_ctz(i)];
Loop (i,0,n) {
memset(dp[!(i&1)], 0, sizeof(dp[0]));
Loop (j,1,1<<m) {
if (sum[j] == a[i]) {
int msk = ((1<<m)-1) ^ j;
int k = 1 << __builtin_popcount(msk);
if (i&1) {
Loop (sup, 0, k) {
int tmp = __builtin_ia32_pdep_si(sup, msk);
dp[0][tmp ^ j] |= dp[1][tmp];
}
} else {
Loop (sup, 0, k) {
int tmp = __builtin_ia32_pdep_si(sup, msk);
dp[1][tmp ^ j] |= dp[0][tmp];
}
}
}
}
if (!dp[!(i&1)][(1<<m)-1]) {
cout << "NO\n";
return 0;
}
}
cout << "YES\n";
}
# | 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... |