Submission #875885

#TimeUsernameProblemLanguageResultExecution timeMemory
875885SpicelmdBank (IZhO14_bank)C++17
100 / 100
78 ms82656 KiB
#include <iostream> #include <algorithm> #include <string> #include <sstream> #include <deque> #include <queue> #include <vector> #include <unordered_map> #include <set> #include <iomanip> using namespace std; using lli = long long; using ldb = long double; const int maxN = 20; int g[maxN][1 << maxN]; int a[maxN]; int b[maxN]; vector<int> moncan[maxN]; int n, m; void Input() { cin >> n >> m; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < m; ++i) cin >> b[i]; } void attemp(int i = 0, int mask = 0, int sum = 0) { if (i == m) { for (int i = 0; i < n; ++i) if (a[i] == sum) moncan[i].push_back(mask); return; } attemp(i + 1, mask, sum); attemp(i + 1, mask | (1 << i), sum + b[i]); } int f(int i, int mask) { if (i < 0) return true; int& gval = g[i][mask]; if (gval != -1) return gval; gval = false; for (int& submask: moncan[i]) { if ((mask & submask) != submask) continue; int newmask = mask & ~submask; gval = f(i - 1, newmask); if (gval) return true; } return false; } void Solve() { attemp(); for (int i = 0; i < n; ++i) for (int mask = 0; mask < (1 << m); ++mask) g[i][mask] = -1; if (f(n - 1, (1 << m) - 1)) cout << "YES"; else cout << "NO"; } int main() { #ifdef LeMinhDuc freopen("input.txt", "r", stdin); #endif ios_base::sync_with_stdio(false); cin.tie(nullptr); Input(); Solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...