Submission #683107

#TimeUsernameProblemLanguageResultExecution timeMemory
683107brijeshSiwachBank (IZhO14_bank)C++17
100 / 100
538 ms180736 KiB
//----------------------- JAI BABA KI -----------------------// #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<ll,ll> pl; typedef vector<pl> vpl; #define all(x) x.begin(), x.end() #define nl cout<<"\n" #define ar array #define PRECISION 9 #define fast_IO ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) #define clock() cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n" #ifdef LOCAL #include "../Library/debug.h" #else #define dbg(...) "OM BHOLE" #endif //----------------------- ये कर लो पहले -----------------------// const int mxN=1<<21; int n, m, a[mxN], b[mxN], dp[21][mxN]; unordered_map<int,vector<int>> maskp; int go(int pos, int mask){ if(pos==n) return 1; if(dp[pos][mask]==-1){ int ans=0; for(int smask: maskp[a[pos]]){ if(mask&smask) continue; ans|=go(pos+1,mask|smask); } dp[pos][mask]=ans; } return dp[pos][mask]; } void solve(){ 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 i=0;i<1<<m;i++){ int sum=0; for(int j=0;j<m;j++){ if(i&(1<<j)) sum+=b[j]; } maskp[sum].push_back(i); } memset(dp,-1,sizeof(dp)); cout<<(go(0,0)==1?"YES":"NO"); } //----------------------- पढाई कर ले -----------------------// int main(){ if (0) cout<<fixed<<setprecision(PRECISION); fast_IO; int T=1; // cin>>T; // freopen("bank.in", "r",stdin); // freopen("bank.out", "w",stdout); while(T--){ solve(); clock(); } 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...