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>
# define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
// # define int long long
# define fi first
# define se second
using namespace std;
const int N = 2e6 + 7;
const int mod = 1e9 + 7;
// const int INF = 1e18 + 7;
int a[N], b[N], n, m, used[25][N], dp[25][N];
vector < int > vc[25];
string ans = "NO";
int rec( int i, int mask ) {
if ( i == 0 ) {
return 1;
}
if ( used[i][mask] ) {
return dp[i][mask];
}
used[i][mask] = 1;
for ( auto msk: vc[i] ) {
if ( (msk & mask) == msk ) {
int ok = rec( i - 1, mask ^ msk);
if ( ok ) {
dp[i][mask] = 1;
}
}
}
return dp[i][mask];
}
int32_t main() {
speed;
cin >> n >> m;
for ( int i = 1; i <= n; i++ ) {
cin >> a[i];
}
for ( int i = 0; i < m; i++ ) {
cin >> b[i];
}
for ( int i = 1; i <= n; i++ ) {
for ( int msk = 0; msk < (1 << m); msk++ ) {
int cnt = 0;
for ( int j = 0; j < m; j++ ) {
if ( (msk >> j) & 1 ) {
cnt += b[j];
}
}
if ( cnt == a[i]) {
vc[i].push_back(msk);
}
}
}
if ( rec( n, (1 << m) - 1 ) ) {
cout << "YES\n";
}
else {
cout << "NO";
}
}
# | 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... |