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 pair<long long, long long> Point;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define MOD1 1000000009
#define sqr(x) sqr((x)*(x))
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }
#ifdef BE_DEBUG
#define debug(...) cerr << "\033[1;31m(" << #__VA_ARGS__ << "):\033[0m", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
const int N = 1100005;
int n,m;
int a[30], b[30];
vector<int> v[1005];
bool check[N][30], ans;
int go(int val) {
int ret = 0;
int cnt = 0;
while(val > 0) {
if(val % 2 == 1) ret += b[cnt];
val /= 2;
cnt ++;
}
return ret;
}
int main() {
IOS
cin >> n >> m;
for(int i = 0; i < n; i ++) cin >> a[i];
for(int i = 0; i < m; i ++) cin >> b[i];
for(int i = 0; i < (1 << m); i ++) {
int val = go(i);
if(val <= 1000) {
v[val].pb(i);
}
}
for(int i = 0; i < n; i ++) {
if(i == 0) {
for(auto x: v[a[i]]) {
check[x][i] = 1;
if(i == n - 1) ans = 1;
}
continue;
}
//
for(int j = 0; j < (1 << m); j ++) {
if(check[j][i - 1] == 0) continue;
for(auto x: v[a[i]]) {
if((x & j) == 0) {
check[x | j][i] = 1;
if(i == n - 1) ans = 1;
}
}
}
//
}
if(ans == 1) {
cout << "YES";
}
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... |