# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
684133 | kusssso | Bank (IZhO14_bank) | C++17 | 567 ms | 179036 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 21;
int n, m;
int a[N];
int b[N];
vector<int> g[1005];
int dp[1 << N][N];
int cal (int t, int i) {
if (i == n - 1) {
return 1;
}
int &res = dp[t][i + 1];
if (res != -1) return res;
res = 0;
for (auto& nt : g[a[i + 1]]) {
if ((nt & t) == 0) {
res |= cal(t | nt, i + 1);
}
}
return res;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
#define TN "bank"
if (ifstream(TN".in")) {
freopen(TN".in", "r", stdin);
freopen(TN".out", "w", stdout);
}
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
for (int t = 0; t < (1 << m); t++) {
int sum = 0;
for (int i = 0; i < m; i++) {
sum += ((t >> i) & 1) * b[i];
}
if (sum <= 1000) {
g[sum].push_back(t);
}
}
memset(dp, -1, sizeof dp);
cout << (cal(0, -1) ? "YES" : "NO");
return 0;
}
Compilation message (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... |