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>
#include "molecules.h"
#define maxn (int)(1e5+51)
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define endl '\n'
#define ll long long
#define pb push_back
#define ull unsigned long long
#define ii pair<int,int>
#define iii tuple<int,int,int>
#define inf 2000000001
#define mod 1000000007 //998244353
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; }
template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; }
int dp[20005],pos[10001];
vector<int>where[10001];
vector<int> find_subset(int l, int u, vector<int> w) {
for(int i=0;i<20005;i++)dp[i]=-1;
int i=0;
dp[0] = 0;
vector<int>can,aux;can.pb(0);
for(auto x:w){
where[x].pb(i++);
for(auto y:can){
if(x+y<=u&&dp[x+y]==-1){
aux.pb(x+y);
dp[x+y] = y;
}
}
for(auto z:aux)can.pb(z);
aux.clear();
}
vector<int>ans;
for(int i=l;i<=u;i++){
if(dp[i]!=-1){
while(i){
ans.pb(i-dp[i]);
i=dp[i];
}
break;
}
}
for(auto& x:ans)x = where[x][pos[x]++];
return ans;
}
// int main(){
// int l,u,n;cin>>l>>u>>n;
// vector<int>w;
// for(int i=0;i<n;++i){
// int x;cin>>x;w.pb(x);
// }
// vector<int>resp = find_subset(l,u,w);
// if(!sz(resp))cout<<-1;
// else for(auto x:resp)cout<<x<<" ";
// cout<<endl;
// }
# | 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... |