이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define ln '\n'
const int N = 20;
const int LG = 21;
const ll INF = 5e18;
const int MOD = 998244353;
int a[N], b[N], cover[(1<<N)+5], leftover[(1<<N)+5];
bool solve(){
int n, m; cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
memset(cover, -1, sizeof(cover));
memset(leftover, -1, sizeof(leftover));
cover[0] = leftover[0] = 0;
for (int i = 0; i < (1 << m); i++){
// cout << i << ln;
for (int j = 0; j < m; j++){
if (((1 << j) & i) == 0) continue;
// let j be the last banknote in subset i
int prev = i & ~(1 << j);
if (cover[prev] == -1) continue;
int cur = leftover[prev] + b[j];
int target = a[cover[prev]];
if (cur < target) {
// cout << prev << ' ' << cover[prev] << ' ' << cur << ln;
cover[i] = cover[prev];
leftover[i] = cur;
} else if (cur == target){
// cout << prev << ' ' << cover[prev] + 1 << ' ' << 0 << ln;
cover[i] = cover[prev] + 1;
leftover[i] = 0;
}
}
// cout << ln;
if (cover[i] == n) return true;
}
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen("mooyomooyo.in", "r", stdin);
// freopen("mooyomooyo.out", "w", stdout);
// ll T; cin >> T;
// while (T--){
// solve();
// }
// init();
// solve();
cout << (solve()? "YES": "NO") << ln;
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... |