Submission #870892

#TimeUsernameProblemLanguageResultExecution timeMemory
870892sleepntsheepBank (IZhO14_bank)C++17
100 / 100
84 ms8792 KiB
#include <iostream> #include <cstring> #include <vector> #include <algorithm> #include <deque> #include <set> #include <utility> #include <array> using namespace std; #define ALL(x) x.begin(), x.end() #define ShinLena cin.tie(nullptr)->sync_with_stdio(false); using i64 = long long; int n, m, a[21], b[20], dp[1<<20][2]; #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx2,tune=native") int main() { ShinLena; cin >> n >> m; memset(dp, 0x86, sizeof dp); for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 0; i < m; ++i) cin >> b[i]; dp[0][0] = 0; dp[0][1] = 0; for (int j = 0; j < (1 << m); ++j) { for (int k = 0; k < m; ++k) { if (j & (1 << k)) { int p = j&~(1<<k); if (dp[p][0] >= 0) { int l = dp[p][1]; int t[2] = {dp[p][0] + b[k], l}; if (l < n && t[0] == a[l+1]) ++t[1], t[0] = 0; if (t[1] > dp[j][1]) dp[j][0] = t[0], dp[j][1] = t[1]; } } } } cout << &"YES\0NO"[4-(4*(dp[(1<<m)-1][1] == 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...