# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
547948 | mgl_diamond | Bank (IZhO14_bank) | C++14 | 1094 ms | 14984 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 ii = pair<int, int>;
using pd = pair<double, double>;
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << "\n"
#define all(x) x.begin(), x.end()
template<class T> bool umax(T &a, T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool umin(T &a, T b) { if (a>b) { a=b; return 1; } return 0; }
void setIO(string name="") {
ios_base::sync_with_stdio(0); cin.tie(0);
if (name.size()) freopen((name+".inp").c_str(),"r",stdin);
if (name.size()) freopen((name+".out").c_str(),"w",stdout);
}
int n, m;
vector<int> a, b, prv, cur;
vector<vector<int>> dp;
int main() {
setIO("");
cin >> n >> m;
a.resize(n); for(int &x: a) cin >> x;
b.resize(m); for(int &x: b) cin >> x;
///*
dp.resize(1001, vector<int>());
for(int i=0; i<1<<m; ++i) {
int sum=0;
for(int j=0; j<m; ++j) if (i>>j&1)
sum+=b[j];
if (sum<=1000)
dp[sum].push_back(i);
}
//*/
///*
prv.resize(1<<m);
cur.resize(1<<m);
prv[0]=1;
for(int k=0; k<n; ++k) {
for(int i=0; i<1<<m; ++i)
for(int j: dp[a[k]]) if ((j&i)==j)
cur[i]+=prv[i-j];
for(int i=0; i<1<<m; ++i) {
prv[i]=cur[i];
cur[i]=0;
}
}
//*/
for(int i=0; i<1<<m; ++i) if (prv[i]>0) {
cout << "YES\n";
return 0;
}
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... |