Submission #592386

#TimeUsernameProblemLanguageResultExecution timeMemory
592386bLICBank (IZhO14_bank)C++17
100 / 100
114 ms8536 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) (int)(x).size() #define ft first #define sd second #define pb push_back #define endl '\n' typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vii; typedef vector<ll> vl; typedef vector<pair<ll, ll>> vll; #define dgb if(0) const ll MOD = 1e18; const int INF = 1e9; int n, m; void solve(){ cin>>n>>m; int a[n], b[m]; for (int i = 0;i<n;i++) cin>>a[i]; for (int i = 0;i<m;i++) cin>>b[i]; int covered[1<<m]{}, leftover[1<<m]{}; memset(covered, -1, sizeof(covered)); memset(leftover, -1, sizeof(leftover)); covered[0] = leftover[0] = 0; bool ans = false; for (int i = 1;i<(1<<m);i++){ for (int j = 0;j<m;j++){ if (i&(1<<j)){ int pre = i^(1<<j); if (covered[pre]==-1) continue; if (leftover[pre]+b[j]==a[covered[pre]]) { covered[i] = covered[pre]+1; ans|=(covered[i]==n); leftover[i] = 0; } else if (leftover[pre]+b[j]<a[covered[pre]]) { covered[i] = covered[pre]; leftover[i] = leftover[pre]+b[j]; } } } } if (ans) cout<<"YES"; else cout<<"NO"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // freopen("movie.in", "r", stdin); // freopen("movie.out", "w", stdout); int t=1; // cin>>t; while(t--){ solve(); cout<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...