제출 #504950

#제출 시각아이디문제언어결과실행 시간메모리
504950KiriLL1ca은행 (IZhO14_bank)C++17
100 / 100
819 ms8664 KiB
#include <bits/stdc++.h> #define fr first #define sc second #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define pb push_back #define endl '\n' #define pw(x) (1ll << x) #define sz(x) (int)((x).size()) #define sqr(x) ((ll)x)*((ll)x) #define bcnt(X) __builtin_popcountll(X) #define vec vector #pragma GCC optimize ("Ofast") #pragma GCC optimize ("unroll-loops") using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair <int, int> pii; typedef pair <ll, ll> pll; auto rng = bind(uniform_int_distribution<int>(1, 1e9), mt19937(228)); signed main () { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector <int> a (n), b (m); for (auto &i : a) cin >> i; for (auto &i : b) cin >> i; vector <vector <int>> sim (n); for (int msk = 0; msk < pw(m); msk++) { int sum = 0; for (int j = 0; j < m; j++) { if ((msk >> j) & 1) sum += b[j]; } for (int i = 0; i < n; i++) { if (sum == a[i]) sim[i].pb(msk); } } vector <int> dp (pw(m), -1), ndp (pw(m), -1); dp[0] = 0; ndp[0] = 0; for (int i = 0; i < n; i++) { for (int msk = pw(m) - 1; msk >= 0; msk--) { if (dp[msk] != -1) { for (auto p : sim[i]) { if (p & msk) continue; int mask = p | msk; ndp[mask] = max(ndp[mask], dp[msk] + 1); if (ndp[mask] == n) { cout << "YES" << endl; return 0; } } } } dp = ndp; } cout << "NO" << endl; 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...