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 "molecules.h"
#include<bits/stdc++.h>
using namespace std;
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
long dp[30000];
long pre[30000];
long n=w.size();
long a[w.size()];
for(long i=0;i<n;i++)
{
a[i]=w[i];
}
vector<int>ans;
queue<long>q;
for(long i=1;i<30000;i++)
{
pre[i]=0;
dp[i]=0;
}
pre[0]=-1;
dp[0]=1;
long o=-1;
for(long i=0;i<n;i++)
{
for(long y=0;y<u;y++)
{
if(dp[y]==1&&dp[y+a[i]]==0)
{
q.push(y+a[i]);
}
}
while(!q.empty())
{
dp[q.front()]=1;
pre[q.front()]=i;
if(q.front()>=l&&q.front()<=u)
{
o=q.front();
break;
}
q.pop();
}
if(o!=-1)
break;
}
if(o==-1)
return ans;
while(o!=0)
{
ans.push_back(pre[o]);
o-=a[pre[o]];
}
reverse(ans.begin(),ans.end());
return ans;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |