Submission #781516

#TimeUsernameProblemLanguageResultExecution timeMemory
781516mindiyakDetecting Molecules (IOI16_molecules)C++14
100 / 100
44 ms7636 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,left = 0;
    deque<int> answer;
 
    for(ll i=0;i<w.size();i++){
        sum += arr[i].first;
 
        if(l<= sum and sum <= u){
            vector<int> answer;
            for(int j=left;j<i+1;j++){
                answer.pb(arr[j].second);
            }
            return answer;
        }
        
        // cout << arr[i].first << " " << sum << endl;
        while(sum > u){
            sum -= arr[left].first;
            left += 1;
        }
 
        if(l<= sum and sum <= u){
            vector<int> answer;
            for(int j=left;j<i+1;j++){
                answer.pb(arr[j].second);
            }
            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:25:13: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
   25 |         if(l<= sum and sum <= u){
      |            ~^~~~~~
molecules.cpp:25:28: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'int' [-Wsign-compare]
   25 |         if(l<= sum and sum <= u){
      |                        ~~~~^~~~
molecules.cpp:27:29: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
   27 |             for(int j=left;j<i+1;j++){
      |                            ~^~~~
molecules.cpp:34:19: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'int' [-Wsign-compare]
   34 |         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){
      |                        ~~~~^~~~
molecules.cpp:41:29: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
   41 |             for(int j=left;j<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...