제출 #1280370

#제출 시각아이디문제언어결과실행 시간메모리
1280370peanutBank (IZhO14_bank)C++20
52 / 100
1094 ms1204 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() #define fi first #define se second #define pb push_back #define mp make_pair vector<int> dx = {0, 0, 1, -1}; vector<int> dy = {1, -1, 0, 0}; const int maxn = 20 + 5; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; int salary[maxn], notes[maxn]; bool dp[1 << 20]; int main() { ios::sync_with_stdio(false); cin.tie(0); //freopen(".INP", "r", stdin); //freopen(".OUT", "w", stdout); int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) cin >> salary[i]; for (int i = 0; i < m; ++i) cin >> notes[i]; vector<vector<int>> valid(n); for (int i = 0; i < (1 << m); ++i) { int sum = 0; for (int j = 0; j < m; ++j) if (i >> j & 1) sum += notes[j]; for (int j = 0; j < n; ++j) if (sum == salary[j]) valid[j].pb(i); } dp[0] = true; for (int i = 0; i < n; ++i) { for (int j = (1 << m) - 1; j >= 0; --j) { dp[j] = false; for (auto k : valid[i]) if ((k & j) == k) dp[j] |= dp[j ^ k]; } } for (int i = 0; i < (1 << m); ++i) { if (dp[i]) { cout << "YES"; return 0; } } cout << "NO"; 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...