이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template<class T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
bool dp[21][(1 << 21)] = {0};
vector<int> canget[21];
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for(auto& x : a) cin >> x;
for(auto& x : b) cin >> x;
for(int i = 0; i < (1 << m); i++) {
int csum = 0;
for(int j = 0; j < m; j++)
csum += (b[j] * ((i >> j) & 1));
for(int j = 0; j < n; j++)
if(csum == a[j])
canget[j].pb(i);
}
dp[0][0] = true;
for(int i = 0; i < n; i++)
for(int j = 0; j < (1 << m); j++)
if(dp[i][j])
for(auto& x : canget[i])
if((x & j) == 0)
dp[i + 1][(x | j)] = true;
bool ans = false;
for(int i = 0; i < (1 << m); i++) ans |= dp[n][i];
cout << (ans ? "YES\n" : "NO\n");
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... |