답안 #1114457

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114457 2024-11-18T23:23:48 Z Hostek Detecting Molecules (IOI16_molecules) C++17
컴파일 오류
0 ms 0 KB
// https://oj.uz/problem/view/IOI16_molecules
// https://ioinformatics.org/files/ioi2016problem1.pdf

// #define GARY_DBG

#include <bits/stdc++.h>
#ifndef GARY_DBG
#include "molecules.h"
#endif

using namespace std;

#define int long long

constexpr int sizik = 1000 * 1001;

#define ar std::array
#define pr std::pair
#define vec std::vector

typedef vec<vec<int>> _kra;

std::vector<int> find_subset(int l, int u, std::vector<int> w) {
    int n = (int)w.size();
    std::vector<ar<int, 2>> local_w;
    for (int i = 0; i < n; i++) {
        local_w.push_back({w[i], i});
    }

    std::sort(local_w.begin(), local_w.end());

    std::deque<int> ans;

    int p = 0, k = -1, sum = 0;
    while (k < n) {
        if (l <= sum && sum <= u) {
            // conv ans to vector;
            std::vector<int> rans;
            for (const auto& a : ans) {
                rans.push_back(a);
            }
            std::sort(rans.begin(), rans.end());
            return rans;
        } else if ((k < p) || (sum < l)) {
            k++;
            if (k >= n) break;
            ans.push_back(local_w[k][1]);
            sum += local_w[k][0];
        } else if (sum > u) {
            // remove first element.
            ans.pop_front();
            sum -= local_w[p][0];
            p++;
        }
    }

    return std::vector<int>(0);
}

#ifdef GARY_DBG

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> w(n);
    for (auto& a : w) {
        std::cin >> a;
    }

    int l, u;
    std::cin >> l >> u;

    const auto res = find_subset(l, u, w);

    if (res.size() == 0) {
        std::cout << "RETURNED EMPTY VECTOR (...)\n";
        return;
    }

    std::cout << "res ~> ";
    for (const auto& a : res) {
        std::cout << a << " ";
    }
    std::cout << '\n';
    // check if condition met:
    int sum = 0;
    for (const auto& a : res) {
        sum += w[a];
    }

    if (l <= sum && sum <= u) {
        std::cout << "YES: SOLUTION CORRECT\n";
    } else {
        std::cout << "l: " << l << " | u: " << u << " " << " | got: " << sum << '\n';
    }
    std::cout << l << " <= " << sum << " <= " << u << '\n';
}

int32_t main() {
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.tie(0);

    int t = 1;
    // std::cin >> t;

    for (; t > 0; t--) {
        solve();
    }

    return 0;
}

#endif

Compilation message

/usr/bin/ld: /tmp/cctfeS3c.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