Submission #871945

#TimeUsernameProblemLanguageResultExecution timeMemory
871945chuongdanBank (IZhO14_bank)C++14
100 / 100
96 ms8820 KiB
#include <bits/stdc++.h> #define N 20 #define fi first #define se second #define pb push_back #define mp make_pair #define rep(i, l, r) for(int i = l; i <= r; i++) #define rep2(i, l, r) for(int i = r; i >= l; i--) using namespace std; typedef pair<int,int> ii; typedef pair<ii,int> iii; typedef pair<ii, ii> iv; typedef unsigned long long ull; const int MOD = 1e9 + 7; const int inf = 1e9; const bool multi_test = false; const string NAME = "bt"; int exp(int x, int y){ int res = 1; while (y){ if (y & 1) res = res * x % MOD; x = x * x % MOD; y >>= 1; } return res; } int n, m; int a[N+5], b[N+5]; struct info{ int val = 0, left = 0; bool operator < (info y){ if (val == y.val) return left < y.left; return val < y.val; } } dp[(1<<N)+5]; void solve(){ cin >> n >> m; rep(i, 1, n) cin >> a[i]; rep(i, 1, m) cin >> b[i]; rep(mask, 1, (1<<m) - 1){ rep(i, 1, m){ if ((mask >> (i - 1)) & 1){ info k = dp[mask ^ (1<<(i-1))]; if (k.left + b[i] == a[k.val + 1]){ k.val ++; k.left = 0; } else { k.left += b[i]; } if (dp[mask] < k) dp[mask] = k; } } } if (dp[(1<<m) - 1].val == n) cout << "YES"; else cout << "NO"; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; if (multi_test) cin >> t; while (t--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...