제출 #858794

#제출 시각아이디문제언어결과실행 시간메모리
858794phongcd은행 (IZhO14_bank)C++14
100 / 100
359 ms111188 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define ull unsigned long long #define ii pair <int, int> #define ill pair <ll, ll> #define ild pair <ld, ld> #define fi first #define se second #define all(x) x.begin(), x.end() #define file "test" using namespace std; const int N = 22; const ll MOD = 998244353; const ll INF = 1e18; const ll base = 311; const int BLOCK_SIZE = 400; int n, m; int a[N], b[N], f[N][1 << N]; vector <int> h[1002]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; int ma = 0; for (int i = 1; i <= n; i ++) cin >> a[i], ma = max(ma, a[i]); for (int i = 0; i < m; i ++) cin >> b[i]; for (int s = 1; s < (1 << m); s ++) { int sum = 0; for (int j = 0; (1 << j) <= s; j ++) if (s >> j & 1) sum += b[j]; if (sum <= ma) h[sum].push_back(s); } f[0][0] = 1; for (int i = 1; i <= n; i ++) for (int s = 0; s < (1 << m); s ++) { if (!f[i - 1][s]) continue; for (int j: h[a[i]]) if ((s & j) == 0) f[i][s | j] = 1; } for (int j = 1; j < (1 << m); j ++) if (f[n][j]) { cout << "YES"; return 0; } cout << "NO"; } /* /\_/\ zzZ (= -_-) / >u >u */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...