# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1103634 | vjudge1 | Bank (IZhO14_bank) | C++14 | 148 ms | 32712 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;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define F first
#define S second
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define pb push_back
const int Inf = 2e9 + 10;
const int Mod = 1e9 + 7;
const int LG = 25;
const int SQ = 400;
const int Alpha = 27;
const int maxN = 25;
const int maxL = 2e6;
const int maxS = 4e4 + 10;
int a[maxN];
int b[maxN];
bool dp[maxL][maxN];
vector <int> sum[maxS];
vector <int> ConvertBinary(int x) {
vector <int> ret;
while(x) {
ret.pb(x%2);
x/=2;
}
return ret;
}
int main() {
IOS;
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i++)
cin >> a[i];
for(int i = 1; i <= m; i++)
cin >> b[i];
for(int i = 0; i < (1 << m); i++) {
vector <int> bin = ConvertBinary(i);
int s = 0;
for(int j = 0; j < sz(bin); j++) {
s += b[j+1] * bin[j];
}
sum[s].pb(i);
}
for(int j = 1; j < (1 << m); j++) {
for(int k : sum[a[1]]) {
if(k|j == j)
dp[j][1] = true;
}
}
for(int i = 2; i <= n; i++) {
for(int j = 1; j < (1 << m); j++) {
for(int k : sum[a[i]]) {
if(k|j == j) {
dp[j][i] = dp[j-k][i-1];
}
}
}
}
if(dp[(1 << n)-1][n])
cout << "YES\n";
else
cout << "NO\n";
}
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... |