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;
#define fixed(n) fixed << setprecision(n)
#define ceil(n, m) (((n) + (m) - 1) / (m))
#define add_mod(a, b, m) (((a % m) + (b % m)) % m)
#define sub_mod(a, b, m) (((a % m) - (b % m) + m) % m)
#define mul_mod(a, b, m) (((a % m) * (b % m)) % m)
#define all(vec) vec.begin(), vec.end()
#define rall(vec) vec.rbegin(), vec.rend()
#define sz(x) int(x.size())
#define debug(x) cout << #x << ": " << (x) << "\n";
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define EPS 1e-9
constexpr int INF = 1 << 30, Mod = 1e9 + 7;
constexpr ll LINF = 1LL << 62;
#define PI acos(-1)
template < typename T = int > using Pair = pair < T, T >;
vector < string > RET = {"NO", "YES"};
template < typename T = int > istream& operator >> (istream &in, vector < T > &v) {
for (auto &x : v) in >> x;
return in;
}
template < typename T = int > ostream& operator << (ostream &out, const vector < T > &v) {
for (const T &x : v) out << x << ' ';
return out;
}
int n, m;
vector < int > a, b;
vector < vector < int > > dp, adj;
int can_do(int idx, int mask){
if(idx == n) return true;
int &ret = dp[idx][mask];
if(~ret) return ret;
ret = false;
for(auto& x : adj[idx]){
if(x & mask) continue;
if(can_do(idx + 1, mask | x))
return ret = true;
}
return ret;
}
void build_adj(){
adj = vector < vector < int > > (n);
for(int i = 0; i < n; i++){
for(int j = 0; j < (1 << m); j++){
int mask = 0, currX = 0;
for(int bit = 0; bit < m; bit++)
if((j >> bit) & 1)
mask |= (1 << bit), currX += b[bit];
if(currX == a[i])
adj[i].push_back(mask);
}
}
}
void Solve(){
cin >> n >> m;
a = vector < int > (n);
b = vector < int > (m);
cin >> a >> b;
dp = vector < vector < int > > (n + 5, vector < int > (1 << m, -1));
build_adj();
cout << RET[can_do(0, 0)] << '\n';
}
int main(){
ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int test_cases = 1;
// cin >> test_cases;
for(int tc = 1; tc <= test_cases; tc++){
// cout << "Case #" << tc << ": ";
Solve();
}
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... |