Submission #781493

#TimeUsernameProblemLanguageResultExecution timeMemory
781493mindiyakDetecting Molecules (IOI16_molecules)C++14
19 / 100
1 ms212 KiB
#include "molecules.h"
#include <algorithm>
#include <vector>
// #include <iostream>

#define ll unsigned long long 
#define mp make_pair
#define pb push_back

using namespace std;

vector<int> find_subset(int l, int u, vector<int> w) {
    vector<pair<ll,ll>> arr;
    for(ll i=0;i<w.size();i++){
        arr.pb(mp(w[i],i));
    }
    sort(arr.begin(),arr.end());
    ll sum = 0;
    vector<int> answer;

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

    for(ll i=0;i<w.size();i++){
        answer.pb(arr[i].second);
        sum += arr[i].first;

        if(l<= sum and sum <= u){
            return answer;
        }
        // cout << arr[i].first << " " << sum << endl;
        while(sum > u){
            sum -= arr[answer[0]].first;
            // cout << "remove " << answer[0] << " by " << arr[answer[0]].first << " to " << sum << endl;
            answer.erase(answer.begin());
        }

        if(l<= sum and sum <= u){
            return answer;
        }
    }
    return vector<int>(0);
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:21:9: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
   21 |     if(l<= sum and sum <= u){
      |        ~^~~~~~
molecules.cpp:21:24: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'int' [-Wsign-compare]
   21 |     if(l<= sum and sum <= u){
      |                    ~~~~^~~~
molecules.cpp:29:13: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
   29 |         if(l<= sum and sum <= u){
      |            ~^~~~~~
molecules.cpp:29:28: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'int' [-Wsign-compare]
   29 |         if(l<= sum and sum <= u){
      |                        ~~~~^~~~
molecules.cpp:33:19: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'int' [-Wsign-compare]
   33 |         while(sum > u){
      |               ~~~~^~~
molecules.cpp:39:13: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
   39 |         if(l<= sum and sum <= u){
      |            ~^~~~~~
molecules.cpp:39:28: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'int' [-Wsign-compare]
   39 |         if(l<= sum and sum <= u){
      |                        ~~~~^~~~
#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...