Submission #1056863

# Submission time Handle Problem Language Result Execution time Memory
1056863 2024-08-13T11:57:20 Z fv3 Detecting Molecules (IOI16_molecules) C++14
Compilation error
0 ms 0 KB
#include "molecules.h"

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define value first 
#define index second 

vector<int> find_subset(int L, int R, vector<int> w_) 
{
    const int N = w_.size();
    vector<pair<int, int>> W(N);
    for (int i = 0; i < N; i++)
        W[i] = {w_[i], i};

    sort(W.begin(), W.end());

    ll sum = 0;
    for (int i = 0; i < N; i++)
    {
        sum += W[i].value;
    }

    if (sum < L || W[0].value > R)
    {
        return {};
    }

    if (sum >= L && sum <= R)
    {
        vector<int> res(N);
        iota(res.begin(), res.end(), 0);
        return res;
    }
    if (W[0].value >= L && W[0].value <= R)
    {
        return {0};
    }

    int mx_cnt = 0;
    sum = 0;

    while (sum + W[mx_cnt].value <= R)
    {
        sum += W[mx_cnt].value;
        mx_cnt++;
    }

    int mn_cnt = 1;
    int back = N - 1;
    sum = 0;
    while (sum + W[back].value < L)
    {
        sum += W[back--].value;
        mn_cnt++;
    }

    if (mn_cnt > mx_cnt)
        return {};

    vector<int> res(mn_cnt);
    sum = 0;
    for (int i = 0; i < mn_cnt; i++)
    {
        res[i] = W[i].index;
        sum += W[i].value;
    }

    int l = 0;
    int r = N - 1;
    while (sum < L)
    {
        sum += W[r].value - W[l].value;
        res[l++] = W[r--].index;
    }

    return res;
}
#include "grader.cpp"

Compilation message

/usr/bin/ld: /tmp/ccUMD8gp.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccExDyqp.o:molecules.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status