이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 20;
int n, m;
int a[N], b[N];
pair<int, int> f[1 << N];
void solve() {
for (int mask = 1; mask <= 1 << m; ++mask) {
bool ok = false;
for (int i = 0; i < m; ++i) {
if ((mask >> i & 1) == 0) {
continue;
}
int prev = mask ^ 1 << i;
if (f[prev].first == -1) {
continue;
}
if (f[prev].second + b[i] < a[f[prev].first]) {
f[mask] = {f[prev].first, f[prev].second + b[i]};
ok = true;
break;
} else if (f[prev].second + b[i] == a[f[prev].first]) {
f[mask] = {f[prev].first + 1, 0};
if (f[mask].first == n) {
cout << "YES\n";
return;
}
ok = true;
break;
}
}
if (!ok) {
f[mask].first = -1;
}
}
cout << "NO\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < m; ++i) {
cin >> b[i];
}
solve();
}
# | 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... |