This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
int n, m, a[20], b[20];
pair<int, int> dp[1 << 20];
int main()
{
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < m; i++)
cin >> b[i];
dp[0] = {0, 0};
for (int mask = 1; mask < (1 << m); mask++)
{
for (int i = 0; i < m; i++)
{
auto [nxt, aux] = dp[mask ^ (1 << i)];
if (mask & (1 << i))
dp[mask] = max(dp[mask], mp(nxt + (aux + b[i] == a[nxt]), (aux + b[i]) * (aux + b[i] != a[nxt])));
}
if (dp[mask].first == n)
return cout << "YES\n", 0;
}
cout << "NO\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |