# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
835274 | Anthony_Liu | Bank (IZhO14_bank) | C++11 | 91 ms | 8540 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;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
//#pragma GCC optimization ("unroll-loops")
#define f first
#define s second
#define ll long long
#define pb push_back
#define pi pair <int,int>
#define vi vector <int>
#define size(x) (int)(x).size()
#define all(x) x.begin(), x.end()
void setIO(string name = "") {
cin.tie(0)->sync_with_stdio(0);
if (size(name)) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
}
int N, M;
vi a, b;
int main()
{
//setIO();
cin >> N >> M;
a.resize(N);
b.resize(M);
for (auto &ww : a) cin >> ww;
for (auto &ww : b) cin >> ww;
vector <pi> dp(1 << M, make_pair(INT_MAX, 0));
//on '.f' th person, that person already paid '.s'
dp[0] = {0, 0};
for (int mask = 0; mask < (1 << M); mask++) {
for (int i = 0; i < M; i++) {
if (mask & (1 << i)) continue;
int newmask = mask | (1 << i);
int nf = dp[mask].f;
if (nf == INT_MAX) continue;
int ns = dp[mask].s + b[i];
if (ns > a[nf]) continue;
if (ns == a[nf]) {
nf++;
if (nf == N) {
cout << "YES\n";
return 0;
}
ns = 0;
}
if (make_pair(nf, ns) < dp[newmask])
dp[newmask] = {nf, ns};
}
}
cout << "NO\n";
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... |