Submission #1078409

# Submission time Handle Problem Language Result Execution time Memory
1078409 2024-08-27T16:45:53 Z DrAymeinstein Detecting Molecules (IOI16_molecules) C++17
Compilation error
0 ms 0 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

#include "molecules.h"

using namespace std;

using namespace std;

static vector<int> find_subset(int l, int u, vector<int> w) {
    vector<pair<int, int>> vec;
    int n = w.size();

    for (int i = 0; i < n; i++) {
        vec.push_back({ w[i], i }); // vec = {weight, index)
    }

    // Sort by w[i]
    sort(vec.begin(), vec.end());

    int left = 0, right = 0;
    long long currentSum = vec[0].first;
    bool found = false;

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

    vector<int> result;
    if (found) {
        for (int i = left; i <= right; i++) {
            result.push_back(vec[i].second);
        }
    }

    return result;
}


Compilation message

molecules.cpp:12:20: error: 'std::vector<int> find_subset(int, int, std::vector<int>)' was declared 'extern' and later 'static' [-fpermissive]
   12 | static vector<int> find_subset(int l, int u, vector<int> w) {
      |                    ^~~~~~~~~~~
In file included from molecules.cpp:6:
molecules.h:5:18: note: previous declaration of 'std::vector<int> find_subset(int, int, std::vector<int>)'
    5 | std::vector<int> find_subset(int l, int u, std::vector<int> w);
      |                  ^~~~~~~~~~~