답안 #133919

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
133919 2019-07-21T18:22:44 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(69420);

vector<int> find_subset(int l, int u, vector<int> w)
{
    sort(w.begin(), w.end());

    long long sum = 0;
    for(int i = 0;i<w.size();i++)
    {
        sum += w[i];
    }

    if(sum<l) return vector <int>{};
    if(u<w[0]) return vector <int>{};

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

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

    int tries = 0;

    while(true)
    {
        tries++;
        if(tries>1000) break;

        sum = 0;
        shuffle(v.begin(), v.end(), rnd);

        for(int i = 0;i<v.size();i++)
        {
            sum += v[i].first;
            if(sum>=l && sum<=u)
            {
                for(int j = 0;j<=i;j++)
                {
                    answer.push_back(v[j].second);
                }

                return answer;
            }
            if(sum>u)
            {
                break;
            }
        }
    }

    return vector<int>{};
}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:16:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<w.size();i++)
                   ~^~~~~~~~~
molecules.cpp:27:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<w.size();i++)
                   ~^~~~~~~~~
molecules.cpp:42:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0;i<v.size();i++)
                       ~^~~~~~~~~
/tmp/ccw7Y7ev.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccMBgbQZ.o:molecules.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status