# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1237962 | Jer | 은행 (IZhO14_bank) | C++20 | 1093 ms | 412 KiB |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 25;
int n, m;
int a[MAXN], b[MAXN], used[MAXN];
bool can_pay(int curr)
{
if (curr == n)
return true;
int target = a[curr];
int subset_size = 1 << m;
for (int mask = 1; mask < subset_size; ++mask)
{
int sum = 0;
vector<int> indices;
for (int i = 0; i < m; ++i)
if ((mask >> i) & 1)
{
if (used[i])
{
sum = -1;
break;
}
sum += b[i];
indices.push_back(i);
}
if (sum == target)
{
for (int i : indices)
used[i] = true;
if (can_pay(curr + 1))
return true;
for (int i : indices)
used[i] = false;
}
}
return false;
}
int main()
{
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
for (int i = 0; i < m; i++)
scanf("%d", &b[i]);
sort(a, a + n);
printf("%s\n", (can_pay(0)) ? "YES" : "NO");
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |