# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
376141 | panda | Bank (IZhO14_bank) | C++14 | 67 ms | 86636 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 <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <assert.h>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;
const int MX = 20;
const int MOD = 1e9 + 7;
const int INF = 2e9;
#define F0R(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)x.size()
#define len(x) (int)x.length()
#define rsz resize
#define lb lower_bound
#define ub upper_bound
void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
ios_base::sync_with_stdio(0); cin.tie(0);
if (sz(s)) { setIn(s+".in"), setOut(s+".out"); }
}
int N, M, A[MX], B[MX];
int dp[MX + 1][(1 << MX)];
int main() {
F0R(i, MX + 1) F0R(j, (1 << MX)) dp[i][j] = -1;
cin >> N >> M;
FOR(i, 1, N + 1) cin >> A[i];
FOR(i, 1, M + 1) cin >> B[i];
dp[0][0] = 0;
for (int i = 1; i <= N; i++) {
for (int j = 0; j < (1 << M); j++) if (dp[i - 1][j] == 0) dp[i][j] = dp[i - 1][j] + A[i];
for (int j = 1; j <= M; j++) {
for (int k = 0; k < (1 << M); k++) {
//cout << "on bitmask: " << k << " for " << i << "\n";
if (dp[i][k] != -1 && !(k & (1 << (j - 1))) && dp[i][k] - B[j] >= 0) {
//cout << "Passed bitmask: " << k << "\n";
dp[i][k | (1 << (j - 1))] = dp[i][k] - B[j];
//cout << i << ", " << (k | (1 << (j - 1))) << " has the value: " << dp[i][k | (1 << (j - 1))] << "\n";
}
}
}
}
bool good = 0;
F0R(i, (1 << MX)) if (dp[N][i] == 0) {
good = 1;
//cout << N << " with bitmask " << i << "\n";
//cout << "We've used the notes: \n";
for (int k = 1; k <= M; k++) if (i & (1 << (k - 1))) cout << k << " ";
//cout << "\n";
}
cout << (good ? "YES\n" : "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... |