이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main()
{
size_t n, m;
cin >> n >> m;
vector<unsigned> sal(n), banknotes(m);
for (unsigned &x : sal)
cin >> x;
for (unsigned &x : banknotes)
cin >> x;
vector<pair<size_t, unsigned>> dp(1 << m, {0, 0});
for (unsigned s = 0; s < 1 << m; s++)
{
for (unsigned i = 0; i < m; i++)
{
if (s & (1 << i))
{
if (dp[s ^ (1 << i)].first == n)
dp[s] = {n, 0};
else if (dp[s ^ (1 << i)].second + banknotes[i] == sal[dp[s ^ (1 << i)].first] &&
dp[s ^ (1 << i)].first + 1 > dp[s].first)
dp[s] = {dp[s ^ (1 << i)].first + 1, 0};
else if (dp[s ^ (1 << i)].first >= dp[s].first)
dp[s] = {dp[s ^ (1 << i)].first, dp[s ^ (1 << i)].second + banknotes[i]};
}
}
}
cout << (dp[(1 << m) - 1].first == n ? "YES\n" : "NO\n");
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp: In function 'int main()':
bank.cpp:17:28: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
17 | for (unsigned s = 0; s < 1 << m; s++)
| ~~^~~~~~~~
# | 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... |