# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
328562 | Killer2501 | Bank (IZhO14_bank) | C++14 | 457 ms | 103276 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>
#define ll long long
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define task "bank"
using namespace std;
const int N = 25;
const ll mod = 1e9 + 7;
ll n, m, t, k, a[N], tong, ans, u, v, b[N], pos[N], d[N], dp[21][(1<<21)];
priority_queue< ll, vector<ll>, greater<ll> > pq;
ll c[N];
struct dang
{
ll lc, rc, val, num;
}st[N];
vector<ll> adj[N], kq;
vector<pll> w;
ll pw(ll k, ll n)
{
ll total = 1;
for(; n; n >>= 1)
{
if(n & 1)total = (total * k) % mod;
k = (k * k) % mod;
}
return total;
}
string s;
void sol()
{
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 = 1; i < (1<<m); i ++)
{
ll tong = 0;
for(int j = 0; j < m; j ++)
{
if((i >> j) & 1)tong += b[j+1];
}
for(int j = 1; j <= n; j ++)if(a[j] == tong)adj[j].pb(i);
}
dp[0][0] = 1;
for(int i = 0; i < n; i ++)
{
for(int j = 0; j < (1<<m); j ++)
{
if(dp[i][j] == 0)continue;
for(ll v : adj[i+1])
{
if((j & v) == 0)
{
dp[i+1][(j|v)] = 1;
if(i+1 == n)
{
cout << "YES";
return;
}
}
}
}
}
cout << "NO";
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen(task".in", "r"))
{
freopen(task".in", "r", stdin);
freopen(task".out", "w", stdout);
}
int ntest = 1;
//cin >> ntest;
while(ntest -- > 0)
sol();
}
/*
2 6
9 10
5 4 8 6 2 11
*/
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... |