Submission #906655

#TimeUsernameProblemLanguageResultExecution timeMemory
906655zhasynBank (IZhO14_bank)C++14
71 / 100
1096 ms6748 KiB
#include <bits/stdc++.h> #define pb push_back #define pf push_front using namespace std; #define F first #define S second typedef long long ll; #define pii pair <int, int> #define pll pair <ll, ll> typedef long double ld; const ll N = 1e6 + 1e5 + 10; const ll mod = 998244353; ll um(ll a, ll b){ return ((1LL * a * b) % mod + mod) % mod; } ll subr(ll a, ll b){ return ((1LL * a - b) % mod + mod) % mod; } int a[N], b[N], n, m; bool dp[N], base[N], nw[N]; void calc(int goal, int cur, int sum, int hs){ if(sum == goal){ dp[hs] = true; return; } if(cur == m) return; if(sum + b[cur] <= goal){ calc(goal, cur + 1, sum + b[cur], hs + (1 << cur)); } calc(goal, cur + 1, sum, hs); } void find(int mask, int index, int sum){ //cout << index << " "<< sum << endl; if(index == m){ if(dp[sum] == false) return; if((mask ^ sum) == (mask | sum)) nw[sum | mask] = true; return; } if((mask & (1 << index)) == 0){ find(mask, index + 1, sum + (1 << index)); } find(mask, index + 1, sum); } void subtask1(){ dp[0] = true; for(int i = 0; i < m; i++){ for(int j = a[0]; j >= b[i]; j--){ dp[j] |= dp[j - b[i]]; } } if(dp[a[0]]) cout << "YES"; else cout << "NO"; } void subtask2(){ base[0] = 1; for(int i = 0; i < n; i++){ calc(a[i], 0, 0, 0); for(int mask = 0; mask < (1 << m); mask++){ if(!base[mask]) continue; find(mask, 0, 0); } for(int j = 0; j < (1 << m); j++){ base[j] = nw[j]; nw[j] = false; dp[j] = false; } } bool can = false; for(int i = 0; i < (1 << m); i++){ if(base[i]) can = true; } if(can) cout << "YES\n"; else cout << "NO\n"; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); //freopen("bank.in", "r", stdin); //freopen("bank.out", "w", stdout); cin >> n >> m; for(int i = 0; i < n; i++){ cin >> a[i]; } for(int i = 0; i < m; i++){ cin >> b[i]; } if(m < n){ cout << "NO"; return 0; } if(n == 1){ subtask1(); } else{ subtask2(); } 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...