제출 #1107280

#제출 시각아이디문제언어결과실행 시간메모리
1107280vjudge1은행 (IZhO14_bank)C++17
71 / 100
1085 ms4856 KiB
#include <bits/stdc++.h> // #define int long long using namespace std; const int N = 1e5 + 11; const int maxn = 1e6 + 11; const int inf = 1e9 + 7; const int MOD = 1e9 + 7; int n, m, a[N], b[N], ok = 0; int ps[(1 << 20)]; void f(int pos, int mm){ if(pos == n + 1) ok = 1; if(ok) { return; } for(int mask = 0; mask < (1 << m); mask++){ int sum = ps[mask]; if(mask & mm) continue; if(sum == a[pos]) f(pos + 1, (mask | mm)); if(ok){ return; } } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 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 mask = 0; mask < (1 << m); mask++){ int sum = 0; for(int i = 0; i < m; i++){ if(mask >> i & 1) sum += b[i]; } ps[mask] = sum; } f(0, 0); cout << (ok? "YES":"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...