Submission #88358

#TimeUsernameProblemLanguageResultExecution timeMemory
88358amiratouDetecting Molecules (IOI16_molecules)C++14
Compilation error
0 ms0 KiB
#include <cstdio>
#include <vector>
#include <cassert>
#include <bits/stdc++.h>
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#include "molecules.h"
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
using namespace std;
#include "molecules.h"
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
vector<int> ans;
vector<pair<int,int> > vec;
void process(int j,int i){
	for (int idx = j; idx <= i ; ++idx)
		ans.push_back(vec[idx].se);
}
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
	vec.resize(w.size());
	for (int i = 0; i < w.size(); ++i)
	{
		vec[i].fi=w[i];
		vec[i].se=i;
	}
	sort(vec.begin(),vec.end());
	if(vec[0].fi>=l&&vec[0].fi<=u){
		process(0,0);
		return ans;
	}
	for (int i = 1; i < w.size(); ++i){
		vec[i].fi+=vec[i-1].fi;
		if(vec[i].fi>=l&&vec[i].fi<=u){
			process(0,i);
			return ans;
		}
	}
	/*cout<<"\n";
	for (int i = 0; i < w.size(); ++i)
	{
		cout<<vec[i].fi<<" ";
	}
	cout<<"\n";*/
	for (int i = 0; i < w.size(); ++i)
	{
		if(vec[i].fi>u){
			auto search=lower_bound(vec.begin(),vec.begin()+i,make_pair(vec[i].fi-l,0));
			//debugs(vec[i].fi,search-vec.begin());
			if(search==vec.begin()+i) continue;
			//debugs(vec[i].fi-l,(vec[i].fi-search->fi));
			if(search->fi!=vec[i].fi-l){
				if(search->fi>vec[i].fi-l&&search!=vec.begin())
					search--;
			}
			if((vec[i].fi-search->fi)>=l&&(vec[i].fi-search->fi)<=u){
				process((search-vec.begin())+1,i);
				return ans;
			}
		}
	}
    return vector<int>(0);
}
int main() {
    int n, l, u;
    assert(3 == scanf("%d %d %d", &n, &l, &u));
    std::vector<int> w(n);
    for (int i = 0; i < n; i++)
        assert(1 == scanf("%d", &w[i]));
    std::vector<int> result = find_subset(l, u, w);
    
    printf("%d\n", (int)result.size());
    for (int i = 0; i < (int)result.size(); i++)
        printf("%d%c", result[i], " \n"[i == (int)result.size() - 1]);
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:23:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < w.size(); ++i)
                  ~~^~~~~~~~~~
molecules.cpp:33:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 1; i < w.size(); ++i){
                  ~~^~~~~~~~~~
molecules.cpp:46:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < w.size(); ++i)
                  ~~^~~~~~~~~~
/tmp/cc6WGup1.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccE2cRH2.o:molecules.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status