# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
723480 | PanosPask | Bank (IZhO14_bank) | C++14 | 1078 ms | 1004 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define MAXN 20
#define CHECK_BIT(var, pos) (var & (1 << pos))
using namespace std;
int n, m;
// dp[i]: Contains all of the possible remaining sets of banknotes after serving the first i customers
unordered_set<int> dp[MAXN + 2];
vector<int> accept_by[MAXN + 2];
int notes[MAXN + 2];
int reqs[MAXN + 2];
int calc_sum_by_subset(int s)
{
int ans = 0;
for (int i = 0; i < m; i++)
if (CHECK_BIT(s, i))
ans += notes[i];
return ans;
}
int main(void)
{
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++)
scanf("%d", &reqs[i]);
for (int j = 0; j < m; j++)
scanf("%d", ¬es[j]);
int start = 0; // No notes used
dp[0].insert(start);
// For each customer, calculate all the acceptable sets of notes that would equate to their salary
for (int i = 1; i <= n; i++) {
for (int s = 0; s < (1<<m); s++) {
if (calc_sum_by_subset(s) == reqs[i])
accept_by[i].push_back(s);
}
}
// See if there are any distinct subsets
for (int i = 1; i <= n; i++) {
for (auto to_add : accept_by[i])
for (auto have_used : dp[i-1]) {
// Check if any note is already used
if ((to_add ^ have_used) != to_add + have_used)
continue;
// Add the current combination of notes
dp[i].insert(to_add ^ have_used);
}
}
bool ans = !dp[n].empty();
if (ans)
printf("YES\n");
else
printf("NO\n");
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... |