이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fr first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define endl '\n'
#define pw(x) (1ll << x)
#define sz(x) (int)((x).size())
#define sqr(x) ((ll)x)*((ll)x)
#define bcnt(X) __builtin_popcountll(X)
#define vec vector
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
auto rng = bind(uniform_int_distribution<int>(1, 1e9), mt19937(228));
signed main ()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m; cin >> n >> m;
vector <int> a (n), b (m);
for (auto &i : a) cin >> i;
for (auto &i : b) cin >> i;
vector <vector <int>> sim (n);
for (int msk = 0; msk < pw(m); msk++) {
int sum = 0;
for (int j = 0; j < m; j++) {
if ((msk >> j) & 1) sum += b[j];
}
for (int i = 0; i < n; i++) {
if (sum == a[i]) sim[i].pb(msk);
}
}
vector <int> dp (pw(m), -1);
dp[0] = 0;
for (int i = 0; i < n; i++) {
for (int msk = pw(m) - 1; msk >= 0; msk--) {
if (dp[msk] != -1) {
for (auto p : sim[i]) {
if (p & msk) continue;
int mask = p | msk;
dp[mask] = max(dp[mask], dp[msk] + 1);
if (dp[mask] == n) {
cout << "YES" << endl;
return 0;
}
}
}
}
}
cout << "NO" << endl;
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... |