Submission #864677

#TimeUsernameProblemLanguageResultExecution timeMemory
864677LibDetecting Molecules (IOI16_molecules)C++14
9 / 100
1 ms2648 KiB
#include <bits/stdc++.h>
#include "molecules.h"
using namespace std;
int val[200003];
pair <int,int> val2[200003];

vector <int> find_subset(int l, int u, vector <int> w){
	for(int i=0;i<w.size();i++){
		val[i+1]=w[i];
		val2[i+1]={val[i+1],i+1};
	}
	sort(val2+1,val2+w.size()+1);
	int p1=1,p2=1;
	vector <int> ans;
	long long curweight=0;
	while(p2<=w.size()&&curweight<l){
		curweight+=val2[p2].first;
		p2++;
	}
	if(curweight>=l&&curweight<=u){
		for(int i=p1;i<p2;i++){
			ans.push_back(val2[i].second-1);
		}
		return ans;
	}else{
		p2--;
		curweight-=val2[p2].first;
		while(p2<=w.size()){
			p2++;
			curweight+=val2[p2].first;
			while(curweight>u&&p1<=p2){
				curweight-=val2[p1].first;
				p1++;
			}
			if(curweight>=l&&curweight<=u){
				for(int i=p1;i<=p2;i++){
					ans.push_back(val2[i].second-1);
				}
			return ans;
			}
		}
		return ans;
	}
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:8:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |  for(int i=0;i<w.size();i++){
      |              ~^~~~~~~~~
molecules.cpp:16:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |  while(p2<=w.size()&&curweight<l){
      |        ~~^~~~~~~~~~
molecules.cpp:28:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |   while(p2<=w.size()){
      |         ~~^~~~~~~~~~
#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...