답안 #138300

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
138300 2019-07-29T17:11:18 Z vince Detecting Molecules (IOI16_molecules) C++14
0 / 100
2 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 {};

	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++) 
                 ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB OK (n = 1, answer = NO)
2 Correct 2 ms 504 KB OK (n = 1, answer = NO)
3 Incorrect 2 ms 376 KB Integer 1 violates the range [0, 0]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Contestant can not find answer, jury can
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB OK (n = 1, answer = NO)
2 Correct 2 ms 504 KB OK (n = 1, answer = NO)
3 Incorrect 2 ms 376 KB Integer 1 violates the range [0, 0]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB OK (n = 1, answer = NO)
2 Correct 2 ms 504 KB OK (n = 1, answer = NO)
3 Incorrect 2 ms 376 KB Integer 1 violates the range [0, 0]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB OK (n = 1, answer = NO)
2 Correct 2 ms 504 KB OK (n = 1, answer = NO)
3 Incorrect 2 ms 376 KB Integer 1 violates the range [0, 0]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB OK (n = 1, answer = NO)
2 Correct 2 ms 504 KB OK (n = 1, answer = NO)
3 Incorrect 2 ms 376 KB Integer 1 violates the range [0, 0]
4 Halted 0 ms 0 KB -