Submission #240238

#TimeUsernameProblemLanguageResultExecution timeMemory
240238Dremix10Detecting Molecules (IOI16_molecules)C++17
31 / 100
148 ms65540 KiB
#include "molecules.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; #define F first #define S second //#define endl '\n' #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define maxp 22 #define EPS (ld)(1e-18) #define mod (int)(1e9+7) #define N (int)(1e5+1) bool dp[10005][10005]; vector<int> find_subset(int l, int r, vector<int> w) { int n=w.size(); int i,j; pair<int,int> arr[n]; for(i=0;i<n;i++) arr[i]={w[i],i}; sort(arr,arr+n,greater<pair<int,int> >()); dp[0][0]=true; for(i=1;i<=n;i++) for(j=0;j<=10000;j++){ dp[i][j]|=dp[i-1][j]; if(j>=arr[i-1].F) dp[i][j]|=dp[i-1][j-arr[i-1].F]; } int k; for(k=l;k<=r;k++) if(dp[n][k]){ //cout<<n<<" "<<k<<endl; vector<int> ans; int num=k; int row=n; while(num>0){ assert(row>0); for(i=row;i>0;i--) if(num>=arr[i-1].F) if(dp[i-1][num-arr[i-1].F]){ row=i-1; num-=arr[i-1].F; ans.push_back(arr[i-1].S); break; } } return ans; } return vector<int>(0); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...