이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#pragma GCC optimize("03,unroll-loops")
#pragma GCC target("avx2,bmi2,bmi,lzcnt,popcnt")
#define endl "\n"
#define rs resize
#define pb push_back
#define gcd __gcd
using namespace std;
vector<vector<int>> vv;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int n, m; cin >> n >> m;
vector<int> a, b;
a.rs(n), b.rs(m), vv.rs(30);
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = 0; i < m; ++i) cin >> b[i];
pair<int, int> p[(1 << m)];
int visited[1 << m];
memset(visited, 0, sizeof(visited));
visited[0] = 1, p[0] = {0, 0};
for (int i = 0; i < (1 << m); ++i) vv[__builtin_popcount(i)].pb(i);
for (int i = 0; i < m; ++i) {
for (auto it : vv[i]) {
if (visited[it]) {
if (p[it].first == n) {
cout << "YES";
return 0;
}
int x = p[it].first;
for (int j = 0; j < m; ++j) {
int y = it | (1 << j);
if (it - y) {
if (p[it].second + b[j] > a[x]) continue;
visited[y] = 1;
p[y] = {x, p[it].second + b[j]};
if (a[x] == p[it].second + b[j]) p[y] = {x + 1, 0};
}
}
}
}
}
cout << "NO";
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... |