Submission #781509

#TimeUsernameProblemLanguageResultExecution timeMemory
781509mindiyakDetecting Molecules (IOI16_molecules)C++14
19 / 100
1 ms212 KiB
#include "molecules.h"
#include <algorithm>
#include <vector>
#include <deque>
// #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;
    deque<int> answer;
 
    for(ll i=0;i<w.size();i++){
        answer.pb(arr[i].second);
        sum += arr[i].first;
 
        if(l<= sum and sum <= u){
            vector<int> answer1 (answer.begin(),answer.end());
            return answer1;
        }
        
        // 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.pop_front();
        }
 
        if(l<= sum and sum <= u){
            vector<int> answer1 (answer.begin(),answer.end());
            return answer1;
        }
    }
    return vector<int>(0);
}

Compilation message (stderr)

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