Submission #783611

#TimeUsernameProblemLanguageResultExecution timeMemory
783611acatmeowmeowBank (IZhO14_bank)C++11
100 / 100
112 ms16716 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 20; int n, m, dp[1ll << N], remain[1ll << N], arr[N], note[N]; bool set_bit(int mask, int k) { return mask & (1ll << k); } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 0; i < m; i++) cin >> note[i]; for (int mask = 0; mask < (1ll << m); mask++) dp[mask] = -1; dp[0] = 0; for (int mask = 0; mask < (1ll << m); mask++) { for (int i = 0; i < m; i++) { if (!set_bit(mask, i)) continue; int pmask = mask ^ (1ll << i), cur = arr[dp[pmask]]; if (dp[pmask] == -1) continue; if (remain[pmask] + note[i] < cur) { dp[mask] = dp[pmask]; remain[mask] = remain[pmask] + note[i]; } else if (remain[pmask] + note[i] == cur) { dp[mask] = dp[pmask] + 1; remain[mask] = 0; } } if (dp[mask] == n) { cout << "YES" << '\n'; return 0; } } cout << "NO" << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...