Submission #170410

#TimeUsernameProblemLanguageResultExecution timeMemory
170410LightningBank (IZhO14_bank)C++14
100 / 100
255 ms14584 KiB
#include <iostream> #include <algorithm> #include <vector> #include <cmath> #include <set> #include <map> #include <iomanip> #include <stack> #include <queue> #include <deque> using namespace std; typedef long long ll; typedef pair <int, int> pii; #define sz(a) (int)a.size() #define all(a) a.begin(), a.end() #define pb push_back #define ppb pop_back #define mkp make_pair #define F first #define S second #define show(a) cerr << #a <<" -> "<< a <<"\n" #define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d)) #define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d)) //#define int ll const int N = 20; const int INF = 1e9; int n, m, a[N], b[N]; vector <int> mask[N]; bool visited[N][(1 << N)]; void rec(int i, int state) { if(i == n) { cout << "YES"; exit(0); } if(visited[i][state]) return; visited[i][state] = true; for(int s : mask[i]) { if(state & s) continue; rec(i + 1, (state | s)); } } int main () { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for(int i = 0; i < n; ++i) { cin >> a[i]; } for(int i = 0; i < m; ++i) { cin >> b[i]; } for(int state = 0; state < (1 << m); ++state) { int sum = 0; for(int i = 0; i < m; ++i) if (state & (1 << i)) sum += b[i]; for(int i = 0; i < n; ++i) if (a[i] == sum) mask[i].pb(state); } rec(0, 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...