이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair <int, int>
#define ill pair <ll, ll>
#define ild pair <ld, ld>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define file "test"
using namespace std;
const int N = 22;
const ll MOD = 998244353;
const ll INF = 1e18;
const ll base = 311;
const int BLOCK_SIZE = 400;
int n, m;
int a[N], b[N], f[N][1 << N];
vector <int> h[1002];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
int ma = 0;
for (int i = 1; i <= n; i ++)
cin >> a[i], ma = max(ma, a[i]);
for (int i = 0; i < m; i ++) cin >> b[i];
for (int s = 1; s < (1 << m); s ++) {
int sum = 0;
for (int j = 0; (1 << j) <= s; j ++)
if (s >> j & 1) sum += b[j];
if (sum <= ma) h[sum].push_back(s);
}
f[0][0] = 1;
for (int i = 1; i <= n; i ++)
for (int s = 0; s < (1 << m); s ++) {
if (!f[i - 1][s]) continue;
for (int j: h[a[i]])
if ((s & j) == 0) f[i][s | j] = 1;
}
for (int j = 1; j < (1 << m); j ++)
if (f[n][j]) {
cout << "YES";
return 0;
}
cout << "NO";
}
/*
/\_/\ zzZ
(= -_-)
/ >u >u
*/
# | 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... |