Submission #138298

# Submission time Handle Problem Language Result Execution time Memory
138298 2019-07-29T17:09:42 Z vince Detecting Molecules (IOI16_molecules) C++14
0 / 100
3 ms 504 KB
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#include <string>
#include <unordered_map>
#include <map>
#include <queue>
#include <set>
#include <stack>

using namespace std;

#define long long long
#define fi first
#define se second
typedef pair<int,int> ii;

int n;
set<ii> st;
vector<int> ans;
vector<ii> vec;

vector<int> find_subset(int l, int u, vector<int> w) 
{
	n = w.size();
	for(int i = 0; i < w.size(); i++) 
		vec.push_back({w[i], i+1});
	sort(vec.begin(), vec.end());


	long sum = 0;
	st.insert({0, n});
	for(int i = n-1; i >= 0; i--)
	{
		sum += vec[i].fi;
		st.insert({sum, i});
	}

	auto it = st.lower_bound({l, -1});
	if(it != st.end() && it->fi <= u)
	{
		// printf("%d\n", it->fi);
		for(int i = it->se; i < n; i++)
			ans.push_back(vec[i].se);
		return ans;
	}
	return {0};

	int pref = 0;
	for(int i = 0; i < n; i++)
	{
		pref += vec[i].fi;
		st.erase({sum, i});

		it = st.lower_bound({l-pref, -1});
		if(it != st.end() && it->fi+pref <= u)
		{
			// printf("%d %d\n", pref, it->fi);
			for(int j = 0; j <= i; j++) 
				ans.push_back(vec[j].se);
			for(int j = it->se; j < n; j++)
				ans.push_back(vec[j].se);
			return ans;
		}

		sum -= vec[i].fi;
	}


    return vector<int>(0);
}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:32:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < w.size(); i++) 
                 ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 504 KB sum of weights should be in [10..12] but it is 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB sum of weights should be in [302..304] but it is 50
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 504 KB sum of weights should be in [10..12] but it is 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 504 KB sum of weights should be in [10..12] but it is 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 504 KB sum of weights should be in [10..12] but it is 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 504 KB sum of weights should be in [10..12] but it is 9
2 Halted 0 ms 0 KB -