Submission #477929

#TimeUsernameProblemLanguageResultExecution timeMemory
477929BackNoobBank (IZhO14_bank)C++14
71 / 100
1088 ms2368 KiB
#include <bits/stdc++.h> #define ll long long #define fi first #define se second #define endl '\n' #define mask(i) (1LL << (i)) #define task "name" #define ull unsigned long long using namespace std; const ll mxN = 220797 + 7; const ll inf = 1e9 + 277; const ll mod = 2147483648; const ll infll = 1e18 + 7; const ll base = 307; template <typename T1, typename T2> bool minimize(T1 &a, T2 b) { if (a > b) {a = b; return true;} return false; } template <typename T1, typename T2> bool maximize(T1 &a, T2 b) { if (a < b) {a = b; return true;} return false; } int a[mxN] , b[mxN] , c[mxN]; int dp[(1 << 20) + 7][22]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); //freopen("task.inp" , "r" , stdin); //freopen("task.out" , "w" , stdout); int n , m; cin >> n >> m; for(int i = 1 ; i <= n ; i++) cin >> a[i]; for(int i = 1 ; i <= m ; i++) cin >> b[i]; queue<pair<int , int>> q; for(int mask = 0 ; mask < (1 << m) ; mask++) { int s = 0; for(int i = 0 ; i < m ; i++) { if(mask & (1 << i)) s += b[i + 1]; } if(s == a[1]) q.push({mask , 2}); } while(!q.empty()) { pair<int , int> u = q.front(); q.pop(); if(u.se == n + 1) { cout << "YES"; return 0; } int cnt = 0; for(int i = 0 ; i < m ; i++) { if(!(u.fi & (1 << i))) { c[cnt] = i; ++cnt; } } for(int mask = 0 ; mask < (1 << cnt) ; mask++) { int s = 0; int submask = 0; for(int i = 0 ; i < cnt ; i++) { if(mask & (1 << i)) { submask |= (1 << c[i]); s += b[c[i] + 1]; } } if(s == a[u.se]) q.push({u.fi | submask , u.se + 1}); } } 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...