답안 #1078393

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1078393 2024-08-27T16:37:52 Z DrAymeinstein Detecting Molecules (IOI16_molecules) C++17
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

static vector<int> find_subset(int l, int u, vector<int> w) {
	int n = w.size();
	vector<pair<int, int>> vec; // vec = <weight, index>
	for (int i = 0; i < n; i++) {
		vec.push_back({ w[i], i });
	}
	sort(vec.begin(), vec.end()); // based on w[i]

	int left = 0, right = 0; // pointers (hash map maybe)

	long long sum = vec[0].first;

	while (right < n) {
		if (sum >= l && sum <= u) {
			vector<int> result;
			for (int i = left; i <= right; i++) {
				result.push_back(vec[i].second);
			}
			return result;
		}

		if (sum < 1 && right + 1 < n) {
			right++;
			sum += vec[right].first;
		}
		else if (sum > u && left < right) {
			sum -= vec[left].first;
			left++;
		}
		else {
			break;
		}
	}

	return {};
}


Compilation message

molecules.cpp:8:20: warning: 'std::vector<int> find_subset(int, int, std::vector<int>)' defined but not used [-Wunused-function]
    8 | static vector<int> find_subset(int l, int u, vector<int> w) {
      |                    ^~~~~~~~~~~
/usr/bin/ld: /tmp/cclj0fI3.o: in function `main':
grader.cpp:(.text.startup+0x18d): undefined reference to `find_subset(int, int, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status