#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define vt vector
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define R_EP(i, a, b, s) for (int i = (a); (s) > 0 ? i < (b) : i > (b); i += (s))
#define R_EP1(e) R_EP(i, 0, e, 1)
#define R_EP2(i, e) R_EP(i, 0, e, 1)
#define R_EP3(i, b, e) R_EP(i, b, e, 1)
#define R_EP4(i, b, e, s) R_EP(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define R_EPC(...) GET5(__VA_ARGS__, R_EP4, R_EP3, R_EP2, R_EP1)
#define rep(...) R_EPC(__VA_ARGS__)(__VA_ARGS__)
#define trav(x, a) for (auto x : a)
template<typename T> inline bool umax(T&x, const T& y) { if (x >= y) return false; x = y; return true; }
template<typename T> inline bool umin(T&x, const T& y) { if (x <= y) return false; x = y; return true; }
const int MOD = int(1e9) + 7;
int N, M, a[20], b[20], prefix[20];
bool can[1 << 20], can2[1 << 20];
vt<int> f[20005];
int main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr);
cin >> N >> M;
rep(i, N) cin >> a[i];
rep(i, M) cin >> b[i];
prefix[0] = a[0];
rep(i, 1, N) prefix[i] = prefix[i - 1] + a[i];
rep(mask, 1 << M) {
int sum = 0;
rep(i, M) {
if (mask >> i & 1) sum += b[i];
}
f[sum].pb(mask);
assert(sum <= 20000);
}
trav(mask, f[prefix[0]]) can[mask] = true;
rep(i, 1, N - 1) {
trav(mask, f[prefix[i]]) {
if (!can[mask]) continue;
trav(mask2, f[prefix[i + 1]]) {
if ((mask2 & mask) == mask) {
can2[mask2] = true;
}
}
}
rep(mask, 1 << M) can[mask] = can2[mask], can2[mask] = false;
}
bool ok = false;
trav(mask, f[prefix[N - 1]]) umax(ok, can[mask]);
cout << (ok ? "YES" : "NO") << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
3 ms |
980 KB |
Output is correct |
5 |
Correct |
64 ms |
7068 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
68 ms |
7216 KB |
Output is correct |
9 |
Correct |
61 ms |
6704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
980 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
3 ms |
980 KB |
Output is correct |
5 |
Correct |
64 ms |
7068 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
68 ms |
7216 KB |
Output is correct |
9 |
Correct |
61 ms |
6704 KB |
Output is correct |
10 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |