# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
125781 | srvlt | 은행 (IZhO14_bank) | C++14 | 1074 ms | 4748 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define endl "\n"
using namespace std;
int n, m, a[20], b[20], s[(1 << 20)];
bitset <(1 << 20)> dp[20];
vector <int> d[20];
char used[1001];
void solve1() {
cin>>m;
for (int i = 0; i < n; i++) {
cin>>a[i];
}
for (int i = 0; i < m; i++) {
cin>>b[i];
}
used[0] = true;
for (int j = 0; j < m; j++) {
for (int i = a[0]; i >= b[j]; i--) {
if (used[i - b[j]]) {
used[i] = true;
}
}
}
if (used[a[0]]) {
cout<<"YES";
} else {
cout<<"NO";
}
}
void solve2() {
cin>>m;
for (int i = 0; i < n; i++) {
cin>>a[i];
}
for (int i = 0; i < m; i++) {
cin>>b[i];
}
for (int i = 0; i < (1 << m); i++) {
for (int j = 0; j < m; j++) {
if (i & (1 << j)) {
s[i] += b[j];
}
}
for (int j = 0; j < n; j++) {
if (s[i] == a[j]) {
d[j].pb(i);
}
}
}
for (int i = 0; i < n; i++) {
dp[i][0] = true;
}
int tmp = (1 << m);
for (int i = 0; i < n; i++) {
for (int j = 1; j < tmp; j++) {
for (int k = 0; k < d[i].size(); k++) {
if ((j & d[i][k]) == d[i][k]) {
if (i > 0) {
if (dp[i - 1][j ^ d[i][k]]) {
dp[i][j] = true;
break;
}
} else {
dp[i][j] = true;
break;
}
}
}
}
}
if (dp[n - 1][tmp - 1]) {
cout<<"YES";
} else {
cout<<"NO";
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
if (n == 1) {
solve1();
} else {
solve2();
}
}
컴파일 시 표준 에러 (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... |