제출 #1275049

#제출 시각아이디문제언어결과실행 시간메모리
1275049almazBank (IZhO14_bank)C++20
71 / 100
1097 ms12380 KiB
#include <bits/stdc++.h> using namespace std; #define int long long // #define endl '\n' #define ff first #define ss second #define pb push_back #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define ar array const int MOD = 1e9 + 7,INF = 1e18, N = 2e5 + 5; /* 5 2 1 2 2 2 3 2 3 4 2 4 5 2 */ int n , m; vector <int> a , b; map <int,vector <int>> mp; int f = 0; void ans(int i, vector <int> use){ for(int j : mp[a[i]]){ int h = 1; for(int k = 0;k < m;k++){ if(1 & (j >> k)){ if(use[k] == 1){ h = 0; } } } if(!h) continue; for(int k = 0;k < m;k++){ if(1 & (j >> k)){ use[k] = 1; } } if(i == n - 1){ f = 1; return; } ans(i + 1, use); for(int k = 0;k < m;k++){ if(1 & (j >> k)){ use[k] = 0; } } } } void solve(){ cin >> n >> m; a.resize(n); b.resize(m); for(int i = 0;i < n;i++){ cin >> a[i]; } for(int i = 0;i < m;i++){ cin >> b[i]; } for(int i = 0;i < (1 << m);i++){ int sum = 0; for(int j = 0;j < m;j++){ if(1 & (i >> j)){ sum += b[j]; } } mp[sum].pb(i); } // cout<<"here"<<endl; vector <int> use(m); ans(0 , use); if(f){ cout<<"YES"<<endl; } else{ cout<<"NO"<<endl; } } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int ti = 1; while (ti--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...