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;
vector < int > vc[N];
string ans = "NO";
bool used[30][N];
void rec( int i, int mask ) {
if ( used[i][mask] ) {
return;
}
used[i][mask] = 1;
if ( i == n + 1 ) {
cout << "YES";
exit(0);
}
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] && !(msk & mask) ) {
rec(i + 1, msk | 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];
}
rec( 1, 0 );
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... |