Submission #879123

#TimeUsernameProblemLanguageResultExecution timeMemory
879123YassirSalamaBank (IZhO14_bank)C++17
71 / 100
1092 ms164692 KiB
#include <iostream> #include <vector> #include <algorithm> #include <unordered_map> #include <set> #include <unordered_set> #include <iomanip> #include <cmath> #include <limits> #include <map> #include <utility> #include <cctype> #include <string> #include <cstring> #include <stack> #include <queue> #include<assert.h> #include <functional> #include <iterator> using namespace std; #define OVL(x,s) for(auto y:x) cout<<y<<s; cout<<"\n"; void dbg_out() { cout << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); } #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__); #define endl "\n" #define pb push_back #define F first #define S second #define ll long long #define mod 1000000007 #define all(v) v.begin(),v.end() #define int long long int dp[20][1<<(20)]; int n,m; vector<int> a,b; void solve(int i,int mask){ if(i>=n){ cout<<"YES"<<endl; exit(0); return; } if(dp[i][mask]!=-1) return; for(int j=0;j<=(1<<m);j++){ if(j&mask) continue; int x=0; for(int k=0;k<m;k++){ if((1<<k)&j) x+=b[k]; } if(x==a[i]){ solve(i+1,(mask|j)); } } dp[i][mask]=1; } signed main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); cin>>n>>m; for(int i=0;i<n;i++) { int x; cin>>x; a.pb(x); } for(int i=0;i<m;i++){ int x; cin>>x; b.pb(x); } memset(dp,-1,sizeof(dp)); solve(0,0); cout<<"NO"<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...