Submission #673334

#TimeUsernameProblemLanguageResultExecution timeMemory
673334beedleBank (IZhO14_bank)C++17
19 / 100
136 ms16736 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]; vector <ll> cancover(1<<m,-1); vector <ll> left(1<<m); rep(mask,0,(1<<m)-1) rep(idx,0,m-1) if(mask&(1ll<<idx)) left[mask]+=notes[idx]; rep(mask,1,(1<<m)-1) { rep(idx,0,m-1) if(mask&(1ll<<idx)) { ll submask=mask^(1ll<<idx); ll next=min(cancover[submask]+1,n-1); if(left[submask]==p[next] || left[submask]+notes[idx]==p[next]) if(next>cancover[mask]) { cancover[mask]=next; left[mask]=left[submask]+notes[idx]-p[next]; } } } bool ans=false; rep(i,0,(1<<m)-1) ans|=(cancover[i]==n-1); cout<<(ans?"YES":"NO"); return 0; } /* 1 5 8 4 2 5 1 3 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...