제출 #434584

#제출 시각아이디문제언어결과실행 시간메모리
434584MohammadAghil은행 (IZhO14_bank)C++14
100 / 100
106 ms8468 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]; rep(b,1,1 << m){ rep(i,0,m){ dp[b].ff = -1; 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)]; dp[b].ss += c[i]; if(dp[b].ss == a[dp[b].ff]) dp[b] = {dp[b].ff + 1, 0}; if(dp[b].ff == n) return cout << "YES\n", 0; break; } } } 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...