Submission #319893

# Submission time Handle Problem Language Result Execution time Memory
319893 2020-11-06T16:55:26 Z tjdgus4384 Detecting Molecules (IOI16_molecules) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#include "molecules.h"
using namespace std;

vector<int> find_subset(int l, int u, vector<int> w) {
    long long sum1, sum2;
    vector<pair<int, int> > v;
    for(int i = 0;i < w.size();i++){
        v.push_back({w[i], i});
    }
    sort(v.begin(), v.end());
    for(int i = 0;i < v.size();i++){
        sum1 += (long long)v[i].first; sum2 += (long long)v[v.size()-1-i].first;
        if(sum1 > u) return vector<int>(0);
        if(sum2 < l) continue;
        else{
            for(int j = i+1;j < v.size();j++){
                if(sum1 >= l){
                    vector<int> ans;
                    for(int k = j-i-1;k <= j-1;k++) ans.push_back(v[k].second);
                    sort(ans.begin(), ans.end());
                    return ans;
                }
                sum1 += (long long)(v[j].first - v[j-i-1].first);
            }
            if(sum1 >= l){
                vector<int> ans;
                for(int k = j-i-1;k <= j-1;k++) ans.push_back(v[k].second);
                sort(ans.begin(), ans.end());
                return ans;
            }
        }
    }
    return vector<int>(0);
}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:8:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     for(int i = 0;i < w.size();i++){
      |                   ~~^~~~~~~~~~
molecules.cpp:12:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int i = 0;i < v.size();i++){
      |                   ~~^~~~~~~~~~
molecules.cpp:17:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |             for(int j = i+1;j < v.size();j++){
      |                             ~~^~~~~~~~~~
molecules.cpp:28:29: error: 'j' was not declared in this scope
   28 |                 for(int k = j-i-1;k <= j-1;k++) ans.push_back(v[k].second);
      |                             ^