제출 #761744

#제출 시각아이디문제언어결과실행 시간메모리
761744Alora은행 (IZhO14_bank)C++17
46 / 100
75 ms1384 KiB
#include <bits/stdc++.h> #define name "cownav" #define fi(i,a,b) for(int i = a; i <= b; i++) #define fid(i,a,b) for(int i = a; i >= b; i--) #define ll long long #define f first #define se second #define pii pair<int, int> #define getbit(i, j) ((i >> j) & 1) #define pb push_back #define all(v) v.begin(), v.end() #define maxn const int M = 1e9 + 7; using namespace std; int n, m, id[1003], a[22]; bool dp[22][1 << 20]; vector <int> luu[22]; signed main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); // freopen(name".in", "r", stdin); // freopen(name".out", "w", stdout); cin >> n >> m; fi(i, 1, n){ int x; cin >> x; id[x] = i; } fi(i, 1, m) cin >> a[i]; fi(msk, 1, (1 << m) - 1){ int sum = 0; fi(i, 0, m - 1) if(getbit(msk, i)) sum += a[i + 1]; if(sum <= 1000 && id[sum] != 0) luu[id[sum]].pb(msk); } fi(i, 1, n) if(luu[i].size() == 0) {cout << "NO"; return 0;} dp[0][0] = 1; fi(i, 1, n){ fi(msk, 0, (1 << m) - 1) if(dp[i - 1][msk]){ for(auto tt: luu[i]) if((msk & tt) == 0){ dp[i][msk + tt] = 1; } } } fi(msk, 1, (1 << m) - 1) if(dp[n][msk]) {cout << "YES"; return 0;} cout << "NO"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...