# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
968297 | tset | Bank (IZhO14_bank) | C++14 | 73 ms | 444 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;
#define int long long
bool dp[(1<<20) +42][21];
signed main()
{
int nbReq, nbBillets;
scanf("%lld%lld", &nbReq, &nbBillets);
const int MX = 1<<nbBillets;
vector<int> req(nbReq);
vector<int> billets(nbBillets);
for(int i=0; i<nbReq; i++)
scanf("%lld", &req[i]);
for(int i=0; i<nbBillets; i++)
scanf("%lld", &billets[i]);
vector<vector<int>> occ(nbReq);
for(int mask=0; mask<=MX; mask++)
{
int sum = 0;
for(int iB=0; iB<nbBillets; iB++)
{
if((mask&(1<<iB)) != 0)
{
sum += billets[iB];
}
}
for(int iR =0; iR < nbReq; iR++)
{
if(req[iR] == sum)
{
occ[iR].push_back(mask);
}
}
}
dp[0][0] = true;
for(int iR =0; iR < nbReq; iR++)
{
for(int mask= 0; mask<= MX; mask++)
{
if(dp[iR][mask])
{
for(int addMask : occ[iR])
{
if((mask & addMask) == 0)
{
dp[iR+1][mask|addMask] = true;
if(iR+1 == nbReq)
{
printf("YES\n");
exit(0);
}
}
}
}
}
}
printf("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... |