Submission #160604

# Submission time Handle Problem Language Result Execution time Memory
160604 2019-10-28T17:43:49 Z nafis_shifat Detecting Molecules (IOI16_molecules) C++14
Compilation error
0 ms 0 KB
#include "molecules.h"
#include<bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
vector<int> find_subset(int l, int u, vector<int> w)
{
	vector<pii> v;
	for(int i=0;i<w.size();i++)v.emplace_back(w[i],i);
	sort(v.begin(),v.end());
    
    vector<int> res;
    int _r=-1;
    for(int i=0;i<v.size();i++)
    {
    	if(v[i].first<=u&&v[i].first>=l)
    	{
    		res.push_back(v[i].second);
    		return res;
    	}
    	if(v[i].first<l)_r=i;
    }

    ll cs=0;
    int _l=-1;
    for(int i=_r;i>=0;i--)
    {
    	cs+=v[i].first;
    	if(cs>=l&&cs<=u)
    	{
    		_l=i;
    		break;
    	}
    	if(cs>u)
    	{
    		cs-=v[_r].first;
    		_r--;
    		if(cs>=l&&cs<=u)
    		{
    			_l=i;
    			break;
    		}
    	}
    }

    if(_l==-1)
    {
    	return res;
    }

    for(int i=_l;i<=_r;i++)res.push_back(v[i].second);
    sort(res.begin(),res.end());
    return res;
}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:8:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<w.size();i++)v.emplace_back(w[i],i);
              ~^~~~~~~~~
molecules.cpp:13:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v.size();i++)
                 ~^~~~~~~~~
molecules.cpp:23:5: error: 'll' was not declared in this scope
     ll cs=0;
     ^~
molecules.cpp:23:5: note: suggested alternative: 'l'
     ll cs=0;
     ^~
     l
molecules.cpp:27:6: error: 'cs' was not declared in this scope
      cs+=v[i].first;
      ^~
molecules.cpp:27:6: note: suggested alternative: 'cos'
      cs+=v[i].first;
      ^~
      cos