이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// uggjaa ped
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(lcv, lower, upper) for (ll lcv = lower; lcv < upper; lcv++)
bool help(vector<vector<ll>> dp, ll i, ll mask, ll a[], ll left, ll b[], ll m, ll n)
{
if (mask == 0)
return false;
if (dp[i][mask] != -1)
return dp[i][mask];
bool ans = false;
loop(j, 0, m)
{
if (((1 << j) & mask))
{
if (left == b[j])
{
if (i == n - 1)
return dp[i][mask] = true;
ans = ans or help(dp, i + 1, mask ^ (1 << j), a, a[i + 1], b, m, n);
}
else if (left > b[j])
{
ans = ans or help(dp, i, mask ^ (1 << j), a, left - b[j], b, m, n);
}
}
}
return dp[i][mask] = ans;
}
void solve()
{
ll n, m;
cin >> n >> m;
ll a[n], b[m];
loop(i, 0, n) cin >> a[i];
loop(i, 0, m) cin >> b[i];
vector<vector<ll>> dp(n, vector<ll>(1 << m, -1));
cout << (help(dp, 0, (1 << m) - 1, a, a[0], b, m, n) ? "YES" : "NO") << endl;
}
int main()
{
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp: In function 'bool help(std::vector<std::vector<long long int> >, long long int, long long int, long long int*, long long int, long long int*, long long int, long long int)':
bank.cpp:22:40: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
22 | return dp[i][mask] = true;
bank.cpp:31:24: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
31 | return dp[i][mask] = ans;
# | 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... |