Submission #640546

#TimeUsernameProblemLanguageResultExecution timeMemory
640546ymmBank (IZhO14_bank)C++17
100 / 100
783 ms6476 KiB
#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") 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; } 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 sup = 0; int k = 1 << __builtin_popcount(((1<<m)-1) ^ j); if (i&1) { Loop (_,0,k) { dp[0][sup ^ j] |= dp[1][sup]; sup = ((sup | j) + 1) & (~j); } } else { Loop (_,0,k) { dp[1][sup ^ j] |= dp[0][sup]; sup = ((sup | j) + 1) & (~j); } } } } if (!dp[!(i&1)][(1<<m)-1]) { cout << "NO\n"; return 0; } } cout << "YES\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...