Submission #994455

#TimeUsernameProblemLanguageResultExecution timeMemory
994455SuPythonyDetecting Molecules (IOI16_molecules)C++17
46 / 100
2 ms796 KiB
#include <bits/stdc++.h>
#include "molecules.h"
using namespace std;
typedef long long ll;

vector<int> find_subset(int d, int u, vector<int> w) {
    vector<pair<int,int>> a;
    int tot=0;
    for (int i=0; i<w.size(); i++) {
        a.push_back({w[i],i});
        tot+=w[i];
    }
    sort(a.begin(),a.end());
    int l=0,r=w.size()-1;
    bool pos=true;
    while (true) {
        if (tot>u) {
            tot-=a[r].first;
            r--;
            if (r<0) {
                pos=false;
                break;
            }
        } else if (tot<d) {
            tot-=a[l].first;
            l++; r++;
            if (l==w.size()||r==w.size()) {
                pos=false;
                break;
            }
            tot+=a[r].first;
        } else {
            break;
        }
    }
    if (!pos) return vector<int>();
    vector<int> ans;
    for (int i=l; i<=r; i++) ans.push_back(a[i].second);
    sort(ans.begin(),ans.end());
    return ans;
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:9:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     for (int i=0; i<w.size(); i++) {
      |                   ~^~~~~~~~~
molecules.cpp:27:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |             if (l==w.size()||r==w.size()) {
      |                 ~^~~~~~~~~~
molecules.cpp:27:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |             if (l==w.size()||r==w.size()) {
      |                              ~^~~~~~~~~~
#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...