Submission #875768

#TimeUsernameProblemLanguageResultExecution timeMemory
875768raul2008487Detecting Molecules (IOI16_molecules)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> #include "molecules.h" #define ll long long #define all(v) v.begin(), v.end() #define pb push_back #define fi first #define se second #define vl vector<ll> using namespace std; bool check(ll cur, ll low, ll high){ return (cur <= high && cur >= low); } vector<int> find_subset(int l, int u, vector<int> w) { vl ans; vector<pair<ll,ll>> p; ll i, j, n = w.size(), left = 0, r = 1; long long sum = w[0]; for(i=0;i<n;i++){ p.pb({w[i], i}); } sort(all(p)); bool flag = 0; while(left <= right){ if(check(sum, l, u)){ break; } else if(sum > u){ if(left == n){ flag = 1; break; } sum -= p[left].fi; left++; } else if(sum < l){ if(right == n){ flag = 1; break; } sum += p[right].fi; right++; } } if(flag){ return ans; } else{ for(i=left;i<right;i++){ ans.pb(p[i].se); } return ans; } }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:23:16: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   23 |     while(left <= right){
      |           ~~~~~^~~~~~~~
molecules.cpp:36:22: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   36 |             if(right == n){
      |                ~~~~~~^~~~
molecules.cpp:40:22: error: invalid conversion from 'std::ios_base& (*)(std::ios_base&)' to 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-fpermissive]
   40 |             sum += p[right].fi;
      |                      ^~~~~
      |                      |
      |                      std::ios_base& (*)(std::ios_base&)
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from molecules.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1043:28: note:   initializing argument 1 of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; std::vector<_Tp, _Alloc>::reference = std::pair<long long int, long long int>&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
molecules.cpp:41:13: warning: ISO C++ forbids incrementing a pointer of type 'std::ios_base& (*)(std::ios_base&)' [-Wpointer-arith]
   41 |             right++;
      |             ^~~~~
molecules.cpp:41:13: error: lvalue required as increment operand
molecules.cpp:45:16: error: could not convert 'ans' from 'vector<long long int>' to 'vector<int>'
   45 |         return ans;
      |                ^~~
      |                |
      |                vector<long long int>
molecules.cpp:48:21: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   48 |         for(i=left;i<right;i++){
      |                    ~^~~~~~
molecules.cpp:51:16: error: could not convert 'ans' from 'vector<long long int>' to 'vector<int>'
   51 |         return ans;
      |                ^~~
      |                |
      |                vector<long long int>
molecules.cpp:16:11: warning: unused variable 'j' [-Wunused-variable]
   16 |     ll i, j, n = w.size(), left = 0, r = 1;
      |           ^
molecules.cpp:16:38: warning: unused variable 'r' [-Wunused-variable]
   16 |     ll i, j, n = w.size(), left = 0, r = 1;
      |                                      ^