Submission #133948

# Submission time Handle Problem Language Result Execution time Memory
133948 2019-07-21T18:46:42 Z stoyan_malinin Detecting Molecules (IOI16_molecules) C++14
9 / 100
798 ms 504 KB
#include "molecules.h"
//#include "grader.cpp"

#include<random>
#include <algorithm>

using namespace std;

mt19937 rnd(6942069);
const int MAXN = 2e5 + 5;

int curr[MAXN];

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>1e7 + 7e6) break;

        sum = 0;
        int index = 0;
        int length = 0;

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

            curr[length] = v[index-1].second;length++;
            sum += v[index-1].first;

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

        if(sum>=l && sum<=u)
        {
            for(int i = 0;i<length;i++)
            {
                answer.push_back(curr[i]);
            }

            return answer;
        }
    }

    tries = 0;
    while(true)
    {
        if(tries>1e7 + 8e6) break;

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

        tries += v.size();
        for(int i = 0;i<v.size();i++)
        {
            tries++;

            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:22:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<w.size();i++)
                   ~^~~~~~~~~
molecules.cpp:28:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<w.size();i++)
                   ~^~~~~~~~~
molecules.cpp:33:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<w.size();i++)
                   ~^~~~~~~~~
molecules.cpp:47:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<w.size();i++)
                   ~^~~~~~~~~
molecules.cpp:64:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(sum<=u && index<v.size())
                         ~~~~~^~~~~~~~~
molecules.cpp:98:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0;i<v.size();i++)
                       ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB OK (n = 1, answer = NO)
2 Correct 2 ms 256 KB OK (n = 1, answer = NO)
3 Correct 2 ms 256 KB OK (n = 1, answer = YES)
4 Correct 2 ms 256 KB OK (n = 2, answer = YES)
5 Correct 2 ms 256 KB OK (n = 2, answer = YES)
6 Correct 2 ms 376 KB OK (n = 3, answer = YES)
7 Correct 2 ms 376 KB OK (n = 3, answer = YES)
8 Correct 2 ms 376 KB OK (n = 3, answer = YES)
9 Correct 2 ms 376 KB OK (n = 3, answer = YES)
10 Correct 2 ms 376 KB OK (n = 3, answer = YES)
11 Correct 2 ms 256 KB OK (n = 3, answer = YES)
12 Correct 2 ms 380 KB OK (n = 3, answer = YES)
13 Correct 576 ms 376 KB OK (n = 3, answer = NO)
14 Correct 2 ms 256 KB OK (n = 3, answer = YES)
15 Correct 2 ms 256 KB OK (n = 3, answer = YES)
16 Correct 2 ms 256 KB OK (n = 3, answer = NO)
17 Correct 2 ms 376 KB OK (n = 3, answer = NO)
18 Correct 798 ms 376 KB OK (n = 100, answer = NO)
19 Correct 400 ms 476 KB OK (n = 100, answer = YES)
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB OK (n = 12, answer = YES)
2 Correct 2 ms 256 KB OK (n = 12, answer = YES)
3 Correct 686 ms 376 KB OK (n = 12, answer = NO)
4 Correct 703 ms 352 KB OK (n = 12, answer = NO)
5 Correct 40 ms 256 KB OK (n = 12, answer = YES)
6 Correct 2 ms 256 KB OK (n = 12, answer = YES)
7 Correct 2 ms 376 KB OK (n = 12, answer = YES)
8 Correct 2 ms 256 KB OK (n = 12, answer = YES)
9 Correct 2 ms 376 KB OK (n = 6, answer = YES)
10 Correct 379 ms 352 KB OK (n = 12, answer = YES)
11 Correct 2 ms 256 KB OK (n = 100, answer = NO)
12 Correct 404 ms 504 KB OK (n = 100, answer = YES)
13 Correct 2 ms 376 KB OK (n = 100, answer = NO)
14 Correct 2 ms 376 KB OK (n = 100, answer = YES)
15 Incorrect 774 ms 376 KB Contestant can not find answer, jury can
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB OK (n = 1, answer = NO)
2 Correct 2 ms 256 KB OK (n = 1, answer = NO)
3 Correct 2 ms 256 KB OK (n = 1, answer = YES)
4 Correct 2 ms 256 KB OK (n = 2, answer = YES)
5 Correct 2 ms 256 KB OK (n = 2, answer = YES)
6 Correct 2 ms 376 KB OK (n = 3, answer = YES)
7 Correct 2 ms 376 KB OK (n = 3, answer = YES)
8 Correct 2 ms 376 KB OK (n = 3, answer = YES)
9 Correct 2 ms 376 KB OK (n = 3, answer = YES)
10 Correct 2 ms 376 KB OK (n = 3, answer = YES)
11 Correct 2 ms 256 KB OK (n = 3, answer = YES)
12 Correct 2 ms 380 KB OK (n = 3, answer = YES)
13 Correct 576 ms 376 KB OK (n = 3, answer = NO)
14 Correct 2 ms 256 KB OK (n = 3, answer = YES)
15 Correct 2 ms 256 KB OK (n = 3, answer = YES)
16 Correct 2 ms 256 KB OK (n = 3, answer = NO)
17 Correct 2 ms 376 KB OK (n = 3, answer = NO)
18 Correct 798 ms 376 KB OK (n = 100, answer = NO)
19 Correct 400 ms 476 KB OK (n = 100, answer = YES)
20 Correct 2 ms 376 KB OK (n = 12, answer = YES)
21 Correct 2 ms 256 KB OK (n = 12, answer = YES)
22 Correct 686 ms 376 KB OK (n = 12, answer = NO)
23 Correct 703 ms 352 KB OK (n = 12, answer = NO)
24 Correct 40 ms 256 KB OK (n = 12, answer = YES)
25 Correct 2 ms 256 KB OK (n = 12, answer = YES)
26 Correct 2 ms 376 KB OK (n = 12, answer = YES)
27 Correct 2 ms 256 KB OK (n = 12, answer = YES)
28 Correct 2 ms 376 KB OK (n = 6, answer = YES)
29 Correct 379 ms 352 KB OK (n = 12, answer = YES)
30 Correct 2 ms 256 KB OK (n = 100, answer = NO)
31 Correct 404 ms 504 KB OK (n = 100, answer = YES)
32 Correct 2 ms 376 KB OK (n = 100, answer = NO)
33 Correct 2 ms 376 KB OK (n = 100, answer = YES)
34 Incorrect 774 ms 376 KB Contestant can not find answer, jury can
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB OK (n = 1, answer = NO)
2 Correct 2 ms 256 KB OK (n = 1, answer = NO)
3 Correct 2 ms 256 KB OK (n = 1, answer = YES)
4 Correct 2 ms 256 KB OK (n = 2, answer = YES)
5 Correct 2 ms 256 KB OK (n = 2, answer = YES)
6 Correct 2 ms 376 KB OK (n = 3, answer = YES)
7 Correct 2 ms 376 KB OK (n = 3, answer = YES)
8 Correct 2 ms 376 KB OK (n = 3, answer = YES)
9 Correct 2 ms 376 KB OK (n = 3, answer = YES)
10 Correct 2 ms 376 KB OK (n = 3, answer = YES)
11 Correct 2 ms 256 KB OK (n = 3, answer = YES)
12 Correct 2 ms 380 KB OK (n = 3, answer = YES)
13 Correct 576 ms 376 KB OK (n = 3, answer = NO)
14 Correct 2 ms 256 KB OK (n = 3, answer = YES)
15 Correct 2 ms 256 KB OK (n = 3, answer = YES)
16 Correct 2 ms 256 KB OK (n = 3, answer = NO)
17 Correct 2 ms 376 KB OK (n = 3, answer = NO)
18 Correct 798 ms 376 KB OK (n = 100, answer = NO)
19 Correct 400 ms 476 KB OK (n = 100, answer = YES)
20 Correct 2 ms 376 KB OK (n = 12, answer = YES)
21 Correct 2 ms 256 KB OK (n = 12, answer = YES)
22 Correct 686 ms 376 KB OK (n = 12, answer = NO)
23 Correct 703 ms 352 KB OK (n = 12, answer = NO)
24 Correct 40 ms 256 KB OK (n = 12, answer = YES)
25 Correct 2 ms 256 KB OK (n = 12, answer = YES)
26 Correct 2 ms 376 KB OK (n = 12, answer = YES)
27 Correct 2 ms 256 KB OK (n = 12, answer = YES)
28 Correct 2 ms 376 KB OK (n = 6, answer = YES)
29 Correct 379 ms 352 KB OK (n = 12, answer = YES)
30 Correct 2 ms 256 KB OK (n = 100, answer = NO)
31 Correct 404 ms 504 KB OK (n = 100, answer = YES)
32 Correct 2 ms 376 KB OK (n = 100, answer = NO)
33 Correct 2 ms 376 KB OK (n = 100, answer = YES)
34 Incorrect 774 ms 376 KB Contestant can not find answer, jury can
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB OK (n = 1, answer = NO)
2 Correct 2 ms 256 KB OK (n = 1, answer = NO)
3 Correct 2 ms 256 KB OK (n = 1, answer = YES)
4 Correct 2 ms 256 KB OK (n = 2, answer = YES)
5 Correct 2 ms 256 KB OK (n = 2, answer = YES)
6 Correct 2 ms 376 KB OK (n = 3, answer = YES)
7 Correct 2 ms 376 KB OK (n = 3, answer = YES)
8 Correct 2 ms 376 KB OK (n = 3, answer = YES)
9 Correct 2 ms 376 KB OK (n = 3, answer = YES)
10 Correct 2 ms 376 KB OK (n = 3, answer = YES)
11 Correct 2 ms 256 KB OK (n = 3, answer = YES)
12 Correct 2 ms 380 KB OK (n = 3, answer = YES)
13 Correct 576 ms 376 KB OK (n = 3, answer = NO)
14 Correct 2 ms 256 KB OK (n = 3, answer = YES)
15 Correct 2 ms 256 KB OK (n = 3, answer = YES)
16 Correct 2 ms 256 KB OK (n = 3, answer = NO)
17 Correct 2 ms 376 KB OK (n = 3, answer = NO)
18 Correct 798 ms 376 KB OK (n = 100, answer = NO)
19 Correct 400 ms 476 KB OK (n = 100, answer = YES)
20 Correct 2 ms 376 KB OK (n = 12, answer = YES)
21 Correct 2 ms 256 KB OK (n = 12, answer = YES)
22 Correct 686 ms 376 KB OK (n = 12, answer = NO)
23 Correct 703 ms 352 KB OK (n = 12, answer = NO)
24 Correct 40 ms 256 KB OK (n = 12, answer = YES)
25 Correct 2 ms 256 KB OK (n = 12, answer = YES)
26 Correct 2 ms 376 KB OK (n = 12, answer = YES)
27 Correct 2 ms 256 KB OK (n = 12, answer = YES)
28 Correct 2 ms 376 KB OK (n = 6, answer = YES)
29 Correct 379 ms 352 KB OK (n = 12, answer = YES)
30 Correct 2 ms 256 KB OK (n = 100, answer = NO)
31 Correct 404 ms 504 KB OK (n = 100, answer = YES)
32 Correct 2 ms 376 KB OK (n = 100, answer = NO)
33 Correct 2 ms 376 KB OK (n = 100, answer = YES)
34 Incorrect 774 ms 376 KB Contestant can not find answer, jury can
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB OK (n = 1, answer = NO)
2 Correct 2 ms 256 KB OK (n = 1, answer = NO)
3 Correct 2 ms 256 KB OK (n = 1, answer = YES)
4 Correct 2 ms 256 KB OK (n = 2, answer = YES)
5 Correct 2 ms 256 KB OK (n = 2, answer = YES)
6 Correct 2 ms 376 KB OK (n = 3, answer = YES)
7 Correct 2 ms 376 KB OK (n = 3, answer = YES)
8 Correct 2 ms 376 KB OK (n = 3, answer = YES)
9 Correct 2 ms 376 KB OK (n = 3, answer = YES)
10 Correct 2 ms 376 KB OK (n = 3, answer = YES)
11 Correct 2 ms 256 KB OK (n = 3, answer = YES)
12 Correct 2 ms 380 KB OK (n = 3, answer = YES)
13 Correct 576 ms 376 KB OK (n = 3, answer = NO)
14 Correct 2 ms 256 KB OK (n = 3, answer = YES)
15 Correct 2 ms 256 KB OK (n = 3, answer = YES)
16 Correct 2 ms 256 KB OK (n = 3, answer = NO)
17 Correct 2 ms 376 KB OK (n = 3, answer = NO)
18 Correct 798 ms 376 KB OK (n = 100, answer = NO)
19 Correct 400 ms 476 KB OK (n = 100, answer = YES)
20 Correct 2 ms 376 KB OK (n = 12, answer = YES)
21 Correct 2 ms 256 KB OK (n = 12, answer = YES)
22 Correct 686 ms 376 KB OK (n = 12, answer = NO)
23 Correct 703 ms 352 KB OK (n = 12, answer = NO)
24 Correct 40 ms 256 KB OK (n = 12, answer = YES)
25 Correct 2 ms 256 KB OK (n = 12, answer = YES)
26 Correct 2 ms 376 KB OK (n = 12, answer = YES)
27 Correct 2 ms 256 KB OK (n = 12, answer = YES)
28 Correct 2 ms 376 KB OK (n = 6, answer = YES)
29 Correct 379 ms 352 KB OK (n = 12, answer = YES)
30 Correct 2 ms 256 KB OK (n = 100, answer = NO)
31 Correct 404 ms 504 KB OK (n = 100, answer = YES)
32 Correct 2 ms 376 KB OK (n = 100, answer = NO)
33 Correct 2 ms 376 KB OK (n = 100, answer = YES)
34 Incorrect 774 ms 376 KB Contestant can not find answer, jury can
35 Halted 0 ms 0 KB -