Submission #879154

#TimeUsernameProblemLanguageResultExecution timeMemory
879154YassirSalamaBank (IZhO14_bank)C++17
71 / 100
1090 ms21040 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[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[mask]!=-1) return; vector<vector<int>> cmaskes(a[i]+10); cmaskes[0].push_back(0); for(int j=0;j<m;j++){ if(mask&(1<<j)) continue; for(int k=a[i]+9;k>=b[j];k--){ // dbg(k-b[j]) for(auto msk:cmaskes[k-b[j]]){ cmaskes[k].push_back((1<<j)|msk); } } } // dbg(a[i]); // OVL(cmaskes[a[i]]," ") for(auto x:cmaskes[a[i]]) solve(i+1,(mask|x)); dp[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...