제출 #988557

#제출 시각아이디문제언어결과실행 시간메모리
988557WaneDetecting Molecules (IOI16_molecules)C++14
컴파일 에러
0 ms0 KiB
#include <algorithm>
#include <queue>
#include <stack>
#include "molecules.h"

#define int long long
#define pp std::pair<int, int>

bool cmp1(pp a, pp b) {
    return a.first > b.first;
}

std::vector<int> find_subset(int l, int u, std::vector<int> w) {
    
    std::vector<pp> wp;
    for (int i = 0; i < w.size(); i++) wp.push_back({w[i], i});
    // Notice that w_max - w_min is always smaller than u - l.

    sort(wp.begin(), wp.end(), cmp1);

    // We can just put ALL things down here first, and 'replace' them until it satisfies the condition;

    std::priority_queue<pp> q;
    std::priority_queue<pp> d;

    //cout << l << ' ' <<  u << '\n';
    int man = 0;
    for (auto a : wp) {
        if (man > l) {
            //cout << a.first << " << D, ";
            d.push(a); // it means 'ready' queue
            continue;
        }
        //cout << a.first << " << Q, ";
        q.push(a); man += a.first;
    }
    //cout << "Man: " << man << '\n';

    if (man < l) {
        return {}; // Impossible!
    }

    while (!d.empty() && man > u) {
        // Replace d's top and q's top, but there's no more usage for q's top so just fuck it off
        auto dt = d.top();
        auto qt = q.top();
        q.pop(); d.pop();
        q.push(dt);
        man -= qt.first - dt.first;
    }

    if (man > u) {
        return {};
    }
    
    std::vector<int> ans;
    while (!q.empty()) {
        ans.push_back(q.top().second);
        //cout << q.top().second << ' ';
        q.pop();
    }
    //cout << '\n';

    return ans;
}

/*
signed main() {
    int n, l, u;
    cin >> n >> l >> u;
    std::vector<int> w(n);
    for (int i = 0; i < n; i++)
        assert(1 == scanf("%d", &w[i]));
    //cout << l << ' ' << u << '\n';
    std::vector<int> result = find_subset(l, u, w);
    
    
    printf("%d\n", (int)result.size());
    for (int i = 0; i < (int)result.size(); i++)
        printf("%d ", result[i]);
}
*/

컴파일 시 표준 에러 (stderr) 메시지

molecules.cpp: In function 'std::vector<long long int> find_subset(long long int, long long int, std::vector<long long int>)':
molecules.cpp:16:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for (int i = 0; i < w.size(); i++) wp.push_back({w[i], i});
      |                     ~~^~~~~~~~~~
/usr/bin/ld: /tmp/ccPojJLw.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