Submission #711922

#TimeUsernameProblemLanguageResultExecution timeMemory
711922thimote75Detecting Molecules (IOI16_molecules)C++14
100 / 100
52 ms5552 KiB

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

using namespace std;

#define di pair<int, int>
#define idata vector<int>
#define ddata vector<di>
#define num long long

idata find_subset(int l, int u, idata weights) {
    int n = weights.size();
    ddata wi_data(n);
    for (int i = 0; i < n; i ++)
        wi_data[i] = { weights[i], i };
    sort(wi_data.begin(), wi_data.end());
    for (int i = 0; i < n; i ++)
        weights[i] = wi_data[i].first;

    num p_sum = 0;
    num s_sum = 0;

    int h;
    for (h = 0; h < weights.size(); h ++) {
        p_sum += weights[h];
        s_sum += weights[n - 1 - h];

        if (p_sum <= u && s_sum >= l) break ;
    }
    h ++; // Here h is the size of the data

    if (!(p_sum <= u && s_sum >= l))
        return idata(0);
    
    num c_sum = 0;
    int index;
    for (index = 0; index < n; index ++) {
        c_sum += weights[index];
        if (index - h >= 0) c_sum -= weights[index - h];

        if (index + 1 >= h && l <= c_sum && c_sum <= u)
            break ;
    }

    idata res (h);
    for (int i = 0; i < h; i ++)
        res[i] = wi_data[index - i].second;

    return res;
}

/*int main () {
    int n, l, u;
    cin >> n >> l >> u;

    idata w (n);
    for (int i = 0; i < n; i ++)
        cin >> w[i];
    
    idata res = find_subset(l, u, w);

    cout << res.size() << endl;
    for (int i = 0; i < res.size(); i ++)
        cout << res[i] << " ";
}*/

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:25:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for (h = 0; h < weights.size(); h ++) {
      |                 ~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...