Submission #258162

#TimeUsernameProblemLanguageResultExecution timeMemory
258162uacoder123Bank (IZhO14_bank)C++14
100 / 100
300 ms82680 KiB
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define FOR(i,a,b) for (auto i = (a); i <= (b); ++i) #define NFOR(i,a,b) for(auto i = (a); i >= (b); --i) #define all(x) (x).begin(), (x).end() #define sz(x) int(x.size()) #define mp(i,a) make_pair(i,a) #define pb(a) push_back(a) #define bit(x,b) (x&(1LL<<b)) typedef long long int lli; typedef pair <int, int> ii; typedef vector <int> vi; int n,arr[20],arr1[20],m; vi al[20]; int dp[21][(1<<21)]; int cal(int i,int a) { if(i>=n) return 1; if(dp[i][a]!=-1) return(dp[i][a]); dp[i][a]=0; for(int j=0;j<al[i].size();++j) if((a|al[i][j])==a&&cal(i+1,a^al[i][j])) return dp[i][a]=1; return dp[i][a]; } int main() { cin>>n>>m; for(int i=0;i<n;++i) cin>>arr[i]; for(int j=0;j<m;++j) cin>>arr1[j]; for(int i=0;i<=(1<<m)-1;++i) { int v=0; for(int j=0;j<m;++j) if(bit(i,j)) v+=arr1[j]; for(int j=0;j<n;++j) { dp[j][i]=-1; if(arr[j]==v) al[j].pb(i); } } if(cal(0,(1<<m)-1)) cout<<"YES"<<endl; else cout<<"NO"<<endl; return 0; }

Compilation message (stderr)

bank.cpp: In function 'int cal(int, int)':
bank.cpp:26:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<al[i].size();++j)
               ~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...