이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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, pick;
vector < int > a, b;
vector < vector < int > > dp, adj;
void get_adj(int x, int id, int idx){
if(x == 0) {
adj[id].push_back(pick);
return;
}
if(idx == m) return;
get_adj(x, id, idx + 1);
pick ^= (1 << idx);
get_adj(x - b[idx], id, idx + 1);
pick ^= (1 << idx);
}
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++){
pick = 0;
get_adj(a[i], i, 0);
}
}
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... |