Submission #53968

#TimeUsernameProblemLanguageResultExecution timeMemory
53968Alexa2001Detecting Molecules (IOI16_molecules)C++17
100 / 100
67 ms34232 KiB
#include "molecules.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;


vector< pair<int,int> > W;
vector<ll> S;

vector<int> solution(int x, int y)
{
    vector<int> ans;
    for(int i=x; i<=y; ++i)
        ans.push_back(W[i].second);
    return ans;
}

vector<int> find_subset(int L, int R, vector<int> w)
{
    int i, j;

    for(i=0; i<w.size(); ++i) W.push_back({w[i], i});
    sort(W.begin(), W.end());

    ll sum = 0;
    for(i=0; i<W.size(); ++i)
    {
        sum += W[i].first;
        S.push_back(sum);
    }

    j = 0;
    while(j<S.size() && S[j] < L) ++j;
    if(j<S.size() && S[j] <= R)
        return solution(0, j);

    for(i=0; i<S.size(); ++i)
    {
        while(j<S.size() && S[j] - S[i] < L) ++j;
        if(j<S.size() && S[j] - S[i] <= R) return solution(i+1, j);
    }

    return vector<int> ();
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:23:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0; i<w.size(); ++i) W.push_back({w[i], i});
              ~^~~~~~~~~
molecules.cpp:27:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0; i<W.size(); ++i)
              ~^~~~~~~~~
molecules.cpp:34:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(j<S.size() && S[j] < L) ++j;
           ~^~~~~~~~~
molecules.cpp:35:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(j<S.size() && S[j] <= R)
        ~^~~~~~~~~
molecules.cpp:38:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0; i<S.size(); ++i)
              ~^~~~~~~~~
molecules.cpp:40:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(j<S.size() && S[j] - S[i] < L) ++j;
               ~^~~~~~~~~
molecules.cpp:41:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(j<S.size() && S[j] - S[i] <= R) return solution(i+1, j);
            ~^~~~~~~~~
#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...