# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
593191 | Do_you_copy | Bank (IZhO14_bank) | C++17 | 31 ms | 8536 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 taskname "test"
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pil = pair <int, ll>;
using pli = pair <ll, int>;
using pll = pair <ll, ll>;
using ull = unsigned ll;
mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count());
ll min(const ll &a, const ll &b){
return (a < b) ? a : b;
}
ll max(const ll &a, const ll &b){
return (a > b) ? a : b;
}
//const ll Mod = 1000000009;
//const ll Mod2 = 999999999989;
//only use when required
const int maxN = 1e5 + 1;
int n, m;
pii dp[1 << 20];
int a[21], b[21];
void Init(){
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 i = 0; i < 1 << m; ++i){
dp[i] = {0, a[0]};
}
for (int i = 0; i < 1 << m; ++i){
int mask = i;
bool flag = 0;
while (mask){
int j = mask & -mask;
if (dp[i ^ j].se != -1){
if (dp[i ^ j].se >= b[__lg(j)]){
dp[i].se = dp[i ^ j].se - b[__lg(j)];
dp[i].fi = dp[i ^ j].fi;
if (!dp[i].se){
++dp[i].fi;
if (dp[i].fi == n){
//bitset <5> foo(i);
//cerr << foo << " ";
cout << "YES\n"; return;
}
dp[i].se = a[dp[i].fi];
}
flag = 1;
break;
}
}
mask ^= j;
}
if (!flag && i) dp[i].se = -1;
//bitset<5> foo(i);
//cerr << foo << " " << dp[i].fi << " " << dp[i].se << "\n";
}
cout << "NO\n";
}
int main(){
if (fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
//freopen(taskname".out", "w", stdout);
}
faster;
ll tt = 1;
//cin >> tt;
while (tt--){
Init();
}
}
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... |