답안 #133933

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
133933 2019-07-21T18:36:53 Z stoyan_malinin Detecting Molecules (IOI16_molecules) C++14
컴파일 오류
0 ms 0 KB
#include "molecules.h"
`//#include "grader.cpp"

#include<random>
#include <algorithm>

using namespace std;

mt19937 rnd(6942069);

int randInRage(int l, int r)
{
    return l + rnd()%(r-l+1);
}

vector<int> find_subset(int l, int u, vector<int> w)
{
    long long sum = 0;
    for(int i = 0;i<w.size();i++)
    {
        sum += w[i];
    }

    int minValue = 1e9;
    for(int i = 0;i<w.size();i++)
    {
        minValue = min(minValue, w[i]);
    }

    for(int i = 0;i<w.size();i++)
    {
        if(w[i]>=l && w[i]<=u)
        {
            return vector <int>{i};
        }
    }

    if(sum<l) return vector <int>{};
    if(u<minValue) return vector <int>{};

    vector <int> answer;
    vector <pair <int, int>> v;

    for(int i = 0;i<w.size();i++)
    {
        if(w[i]<=u) v.push_back({w[i], i});
    }

    sort(v.begin(), v.end());

    long long tries = 0;
    while(true)
    {
        tries++;
        if(tries>3e7) break;

        sum = 0;
        int index = 0;
        answer.clear();

        while(sum<=u && index<v.size())
        {
            tries++;
            index = randInRage(index, v.size()-1) + 1;

            answer.push_back(v[index-1].second);
            sum += v[index-1].first;

            if(sum>=l && sum<=u)
            {
                break;
            }
        }

        if(sum>=l && sum<=u)
        {
            return answer;
        }
    }

    return vector<int>{};
}

Compilation message

molecules.cpp:2:1: error: stray '`' in program
 `//#include "grader.cpp"
 ^
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:19:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<w.size();i++)
                   ~^~~~~~~~~
molecules.cpp:25:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<w.size();i++)
                   ~^~~~~~~~~
molecules.cpp:30:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<w.size();i++)
                   ~^~~~~~~~~
molecules.cpp:44:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<w.size();i++)
                   ~^~~~~~~~~
molecules.cpp:61:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(sum<=u && index<v.size())
                         ~~~~~^~~~~~~~~