Submission #434567

#TimeUsernameProblemLanguageResultExecution timeMemory
434567MohammadAghilBank (IZhO14_bank)C++14
100 / 100
90 ms8492 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,l,r) for(int i = (l); i < r; i++) #define per(i,r,l) for(int i = (r); i >= l; i--) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() #define pb push_back #define ff first #define ss second const ll mod = 1e9 + 7, maxn = 20, inf = 1e9 + 5; int a[maxn], c[maxn]; pair<int, int> dp[1 << maxn]; int main(){ int n, m; cin >> n >> m; rep(i,0,n) cin >> a[i]; rep(i,0,m) cin >> c[i]; dp[0] = {0, 0}; rep(b, 1, 1 << m){ rep(i,0,m){ pair<int, int> df; if((b & (1 << i)) && dp[b ^ (1 << i)].ff != -1){ int t = a[dp[(b ^ (1 << i))].ff] - dp[(b^(1 << i))].ss; if(t < c[i]) continue; dp[b] = dp[(b ^ (1 << i))]; if(t == c[i]){ dp[b].ff++; dp[b].ss = 0; if(dp[b].ff == n) return cout << "YES\n", 0; }else{ dp[b].ss += c[i]; } break; } dp[b].ff = -1; } } // rep(i,0,1 << m){ // rep(j,0,m) cout << (i & (1 << j) ? 1 : 0); // cout << ' ' << i << ' ' << dp[i].ff << ' ' << dp[i].ss << '\n'; // } cout << "NO\n"; 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...