Submission #673321

#TimeUsernameProblemLanguageResultExecution timeMemory
673321beedleBank (IZhO14_bank)C++17
71 / 100
1094 ms3572 KiB
#include <iostream> #include <iomanip> #include <vector> #include <algorithm> #include <set> #include <iterator> #include <stack> #include <map> #include <math.h> #include <bitset> #include <deque> #include <string> #include <tuple> #include <queue> #include <numeric> #include <complex> #include <assert.h> #include <unordered_set> #include <unordered_map> #define ll long long #define ld long long double #define rep(i, a, b) for (long long i = a; i <= b; i++) #define mod 1000000007ll #define INF 1e18 #define pb push_back #define ff first #define ss second #define endl '\n' #define all(x) (x).begin (), (x).end () #define sz(x) (ll) (x).size () #define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin()) #define rank rnk #define log lg #define fast \ ios_base::sync_with_stdio (false); \ cin.tie (NULL); \ cout.tie (NULL) using namespace std; signed main() { fast; // freopen("bank.in","r",stdin); // freopen("bank.out","w",stdout); ll n,m; cin>>n>>m; ll s1=0, s2=0; ll p[n], notes[m]; rep(i,0,n-1) cin>>p[i], s1+=p[i]; rep(i,0,m-1) cin>>notes[i], s2+=notes[i]; if(s1>s2) { cout<<"NO"<<endl; exit(0); } vector <ll> validmasks[n]; rep(i,0,n-1) rep(mask,0,(1<<m)-1) { ll s=0; rep(idx,0,m-1) if(mask&(1ll<<idx)) s+=notes[idx]; if(s==p[i]) validmasks[i].pb(mask); } bool cancover[n][(1<<m)]; rep(i,0,n-1) rep(mask,0,(1<<m)-1) cancover[i][mask]=false; for(auto mask:validmasks[0]) cancover[0][mask]=true; rep(i,1,n-1) rep(mask,0,(1<<m)-1) { for(auto submask:validmasks[i]) if((submask&(~mask))==0) cancover[i][mask]|=cancover[i-1][mask^submask]; } bool ans=false; rep(mask,0,(1<<m)-1) ans|=cancover[n-1][mask]; cout<<(ans?"YES":"NO"); 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...