Submission #330260

#TimeUsernameProblemLanguageResultExecution timeMemory
330260saarthakDetecting Molecules (IOI16_molecules)C++14
9 / 100
1 ms364 KiB
#include <bits/stdc++.h>
#include "molecules.h"

struct weights {
	int wt;
	int idx;
};

bool cmp(weights a, weights b) {
	return (a.wt < b.wt);
}


std::vector<int> find_subset(int l, int u, std::vector<int> w) {
	int n = w.size();
	
	if(l == u) {
		if(l%w[0] == 0 && l/w[0] <= n) {		//all weights equal
			std::vector<int> ans(l/w[0]);
			for(int i = 0; i < l/w[0]; i++)
				ans[i] = i;
			return ans;
		}
		else
			return std::vector<int>();				//no subarray found
	}
	
	
	int total_weight = 0, i = 0;
	std::queue<int> indices;
	
	std::vector<struct weights> wts(n);
	
	for(int i = 0; i < n; i++)
		wts[i] = {w[i], i};
	
	std::sort(wts.begin(), wts.end(), cmp);
	
	while(total_weight < l && i <= n) {
		total_weight += wts[i].wt;
		indices.push(wts[i++].idx);
	}
	i = 0;
	while(total_weight > u  && i <= n) {
		total_weight -= wts[i++].wt;
		indices.pop();
	}
	
	if(total_weight < l || total_weight > u) return std::vector<int>();		//no subarray found
	
	std::vector<int> ans(indices.size());
  	i = 0;
	while(!indices.empty()) {
		ans[i++] = indices.front();
		indices.pop();
	}
	
	return ans;
}
#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...