답안 #959420

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
959420 2024-04-08T07:37:03 Z Mystic03 Detecting Molecules (IOI16_molecules) C++17
컴파일 오류
0 ms 0 KB
#include "molecules.h"
#include <algorithm>

using namespace std;

#define int long long

std::vector<int> find_subset(int l, int u, std::vector<int> w) {
    int p1 = 0;
    int r = 0;
    int n = w.size();
    std::vector<pair<int, int>> ele;
    for (int i = 0; i < n; i++) {
        ele.push_back({ w[i], i });
    }

    sort(ele.begin(), ele.end());
    int currSum = 0;

    while (currSum < l) {
        if (r == ele.size())    return std::vector<int>(0);
        currSum += ele[r].first;
        r++;
    }

    vector<int> res;
    if (currSum <= u) {
        for (int i = 0; i < r; i++) {
            res.push_back(ele[i].second);
        }
        return res;
    }
    r--;
    currSum -= ele[r].first;

    for (int i = r; i < ele.size(); i++) {
        currSum += ele[i].first;
        currSum -= ele[p1++].first;
        if (currSum >= l && currSum <= u) {
            for (int j = p1; j <= i; j++) {
                res.push_back(ele[j].second);
            }
            return res;
        }
    }
    return std::vector<int>(0);
}

Compilation message

molecules.cpp: In function 'std::vector<long long int> find_subset(long long int, long long int, std::vector<long long int>)':
molecules.cpp:21:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |         if (r == ele.size())    return std::vector<int>(0);
      |             ~~^~~~~~~~~~~~~
molecules.cpp:36:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for (int i = r; i < ele.size(); i++) {
      |                     ~~^~~~~~~~~~~~
/usr/bin/ld: /tmp/cc3ahq71.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