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"
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
typedef long long ll;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
// #ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
// sim dor(const c&) { ris; }
};
#ifdef ASJKD
}
#endif
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define read(x) for(auto &i : (x)){cin>>i;}
#define all(x) begin(x), end(x)
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
ll mod = 1e9+7;
int INF = 1e9+1e8+1e7;
ll INF64 = 1e18;
// vector<string> every;
void test_case(int test){
int n,m;
cin>>n>>m;
vector<vector<int>> dp(n+1,vector<int>(1<<m, -1));
vector<int> a(n);
vector<int> b(m);
read(a);
read(b);
dp[0][0] = 0;
for(int i=0;i<n;i++){
for(int j=0;j<1<<m;j++){
if(dp[i][j] == -1){
continue;
}
for(int k=0;k<m;k++){
if((j & (1<<k)) == 0){
if(dp[i][j] + b[k] == a[i]){
dp[i+1][j+(1<<k)] = 0;
} else{
// assert(dp[i][j+(1<<k)] == -1 or dp[i][j+(1<<k)] == dp[i][j]);
dp[i][j+(1<<k)] = dp[i][j] + b[k];
// debug() << imie(b[k]);
// debug() << imie(dp[i][j+(1<<k)]);
}
}
}
}
}
// bool ok = 0;
for(int i=0;i<1<<m;i++){
if(dp[n][i] >= 0){
cout << "YES\n";
return;
}
}
cout << "NO\n";
}
int main(){
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
int t=1;
// cin>>t;
// debug() << imie(every);
// init();
for(int test=1;test<=t;test++){
test_case(test);
}
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... |