Submission #136796

# Submission time Handle Problem Language Result Execution time Memory
136796 2019-07-26T09:15:11 Z StevenH Detecting Molecules (IOI16_molecules) C++14
0 / 100
1000 ms 376 KB
#include "molecules.h"
#include <algorithm>
#include <cstdio>
using namespace std;
struct Seq{
	int val,id;
}seq[200005];

bool comp(Seq x,Seq y)
{
	return x.val<y.val;
}

std::vector<int> find_subset(int l, int u, std::vector<int> w) {
    
    for(int i=0;i<w.size();i++)
    {
    	seq[i].val=w[i];
    	seq[i].id=i;
    }	

    sort(seq,seq+w.size(),comp);

    int left=0,right=0;
    int sum=seq[0].val;
    while(left<=right)
    {
    	//printf("%d %d %d %d %d\n",left,right,sum,l,u);
    	if(sum<l && right<w.size())
    	{
    		right++;
    		sum+=seq[right].val;
    	}
    	else if(sum>u && left<=right)
    	{
    		sum-=seq[left].val;
    		left++;
    	}
    	//printf("%d %d %d %d %d\n",left,right,sum,l,u);
    	else if(l<=sum && sum<=u)break;
    }

    if(!(l<=sum && sum<=u))
    	return vector<int> (0);
    
    vector<int> ans;
    for(int i=left;i<=right;i++)
    {
    	ans.push_back(seq[i].id);
    }
    return ans;
}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:16:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<w.size();i++)
                 ~^~~~~~~~~
molecules.cpp:29:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      if(sum<l && right<w.size())
                  ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1069 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB OK (n = 12, answer = YES)
2 Correct 2 ms 376 KB OK (n = 12, answer = YES)
3 Execution timed out 1072 ms 296 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1069 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1069 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1069 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1069 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -