제출 #907451

#제출 시각아이디문제언어결과실행 시간메모리
907451zhasyn은행 (IZhO14_bank)C++14
100 / 100
98 ms13144 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; int dp[N], last[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]; } bool can = false; for(int mask = 0; mask < (1 << m); mask++){ dp[mask] = -1; } dp[0] = 0; for(int mask = 0; mask < (1 << m); mask++){ for(int dig = 0; dig < m; dig++){ if((mask & (1 << dig)) > 0){ int nw = mask ^ (1 << dig); int mx = dp[nw], rest = last[nw]; if(dp[nw] == -1) continue; if(last[nw] + b[dig] == a[dp[nw]]){ mx++; rest = 0; } else rest += b[dig]; if(mx >= dp[mask]){ dp[mask] = mx; last[mask] = rest; } } } if(dp[mask] == n){ can = true; break; } } if(can) cout << "YES\n"; else 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...