답안 #76088

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
76088 2018-09-12T03:43:50 Z luciocf Detecting Molecules (IOI16_molecules) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "molecules.h"
 
using namespace std;
 
const int MAXN = 2e5+10;
 
typedef long long ll;
 
struct P {
    int ind;
    ll v;
} num[MAXN];
 
bool comp(P a, P b)
{
    return a.v < b.v;
}
 
ll soma[MAXN];
 
int busca(int pos, int k, int n)
{
    int ini = pos, fim = n;
    while (ini <= fim)
    {
        int mid = (ini+fim)>>1;
 
        if (mid == n && soma[mid]-soma[pos-1] <= k) return mid;
        else if (mid == n)
        {
            fim = mid-1;
            continue;
        }
 
        if (soma[mid]-soma[pos-1] <= k && soma[mid+1]-soma[pos-1] <= k) ini = mid+1;
        else if (soma[mid]-soma[pos-1] <= k && soma[mid+1]-soma[pos-1] > k) return mid;
        else if (soma[mid]-soma[pos-1] > k) fim = mid-1;
    }
    return -1;
}
 
int find_subset(int l, int r, int w[], int n, int result[])
{
    for (int i = 1; i <= n; i++)
        num[i].ind = i-1, num[i].v = w[i-1];
    sort(num+1, num+n+1, comp);
 
    for (int i = 1; i <= n; i++)
        soma[i] = soma[i-1]+num[i].v;
 
    int ini = -1, fim = -1;
    for (int i = 1; i <= n; i++)
    {
        int pos = busca(i, r, n);
        if (pos == -1) continue;
 
        if (soma[pos]-soma[i-1] >= l)
        {
            ini = i, fim = pos;
            break;
        }
    }
 
    if (ini == -1)
        return 0;
 
    int ind = -1;
    for (int i = ini; i <= fim; i++)
        result[++ind] = num[i].ind;
    return ind+1;
}

Compilation message

/tmp/ccV9XWEW.o: In function `main':
grader.cpp:(.text.startup+0x152): undefined reference to `find_subset(int, int, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status