제출 #491973

#제출 시각아이디문제언어결과실행 시간메모리
491973MassimilianoFDetecting Molecules (IOI16_molecules)C++14
46 / 100
110 ms1028 KiB
#include "molecules.h"
#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;

struct molecola {
		long long pos;
		long long weight;
	};

bool operator<(const molecola & lhs, const molecola & rhs) {
		return lhs.weight<rhs.weight;
	}

std::vector<int> find_subset(int l, int u, std::vector<int> w) {
	int i, j, k, n, S=0;
	vector<int> t;
	n=w.size();
	
	vector<molecola> V;
	for (i=0; i<n; i++) {
		V.push_back({i, w[i]});
		S+=w[i];
	}
	if (S<l) {
		cerr << "SCENARIO 1" << endl;
		return t;
	}
	sort(V.begin(), V.end());
	
	for (i=0; i<n; i++) {
		cerr << "V[" << i << "] = {" << V[i].pos << ", " << V[i].weight << "}"<< endl;
	}
	
	i=0; S=0;
	while (S<l) {
		S+=V[i].weight;
		i++;
	}
	if (S<=u) {
		for (j=0; j<i; j++) {
			t.push_back(V[j].pos);
		}
		cerr << "SCENARIO 2" << endl;
		return t;
	}
	
	j=0;
	i--;
	S-=V[i].weight;
	
	while (j+i<=n && S<l) {
		S-=V[j].weight;
		S+=V[j+i].weight;
		j++;
	}
	if (j+i>n) {
		cerr << "SCENARIO 3" << endl;
		return t;	
	}
	
	for (k=j; k<j+i; k++) {
		t.push_back(V[k].pos);
	}
	
	cerr << "SCENARIO 4" << endl;
	
    return t;
}
#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...