Submission #921339

#TimeUsernameProblemLanguageResultExecution timeMemory
921339H1HDetecting Molecules (IOI16_molecules)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> #define T "Task" using namespace std; vector<int> find_subset(int l, int u, vector<int> w){ vector<pair<int, int>> a; for(int i = 0; i < w.size(); ++i){ a.push_back({w[i], i}); } sort(a.begin(), a.end(), [](pair<int,int> a1, pair<int,int> a2){ return a1.first < a2.first; }); vector<int> ans; if(u < a[0].first)return ans; long long sum_val = 0; int idL = 0, idR = a.size()-1; vector<bool> ok(w.size(), 0); while(true){ if(idL > idR)break; sum_val += a[idR].first; ok[a[idR].second] = 1; while(sum_val > u && idL < idR){ sum_val -= a[w.size() - idL - 1].first; ok[a[w.size() - idL - 1].second] = 0; if(sum_val >= l sum_val <= u)break; sum_val += a[idL].first; ok[a[idL].second] = 1; ++idL; } --idR; if(sum_val >= l sum_val <= u){ for(int i = 0; i < ok.size(); ++i) if(ok[i])ans.push_back(i); return ans; } } return ans; }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:8:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     for(int i = 0; i < w.size(); ++i){
      |                    ~~^~~~~~~~~~
molecules.cpp:27:28: error: expected ')' before 'sum_val'
   27 |             if(sum_val >= l sum_val <= u)break;
      |               ~            ^~~~~~~~
      |                            )
molecules.cpp:33:24: error: expected ')' before 'sum_val'
   33 |         if(sum_val >= l sum_val <= u){
      |           ~            ^~~~~~~~
      |                        )
molecules.cpp:34:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |             for(int i = 0; i < ok.size(); ++i)
      |                            ~~^~~~~~~~~~~