이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b) - 1; i >= (a); --i)
#define trav(x, v) for (auto &x : v)
#define ff first
#define ss second
using ll = int64_t;
template<class T> bool ckmin(T &a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T &a, const T& b) { return a < b ? a = b, 1 : 0; }
const int N = 20;
int n, m, a[N], b[N];
vector<int> r[N];
int f[N][1 << N];
bool solve(int S, int i) {
if (i == 0) return true;
if (S == 0) return false;
--i;
auto &h = f[i][S];
if (h != -1) return h;
trav(x, r[i])
if ((x & S) == x)
if (solve(S & ~x, i))
return h = true;
return h = false;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
rep(i, 0, n) cin >> a[i];
rep(i, 0, m) cin >> b[i];
rep(S, 0, 1 << m) {
int sum = 0;
rep(j, 0, m) if (S & 1 << j) sum += b[j];
rep(i, 0, n) if (sum == a[i]) r[i].emplace_back(S);
}
rep(S, 0, 1 << m) rep(i, 0, n) f[i][S] = -1;
cout << (solve((1 << m) - 1, n) ? "YES" : "NO");
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp: In function 'bool solve(int, int)':
bank.cpp:31:13: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
return h = true;
~~^~~~~~
bank.cpp:32:11: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
return h = false;
~~^~~~~~~
# | 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... |