Submission #789810

#TimeUsernameProblemLanguageResultExecution timeMemory
789810MalixDetecting Molecules (IOI16_molecules)C++14
Compilation error
0 ms0 KiB
#include "molecules.h" #include <bits/stdc++.h> using namespace std; std::vector<int> find_subset(int l, int u, std::vector<int> w) { int arrSize = w.size(); int gap = u - l; vector<int> answer; vector<int> answertemp; vector<int> temp = w; sort(temp.begin(), temp.end()); if(arrSize == 1){ if(w[0]<=u && w[0]>=l){ answer.push_back(0); return answer; } return std::vector<int>(0); } if(temp[0] == temp[arrSize-1]){ int modval = u%w[0]; if(modval<=gap){ int termcount = (u-modval)/w[0]; if(arrSize>=termcount){ for(int i = 0; i < termcount; i++){ answer.push_back(i); } return answer; } } return std::vector<int>(0); } if(temp[arr-1]-temp[0]==1){ int left = 0; int right = 1; int sum = temp[0]; answertemp.push_back(l); while(sum<u){ sum += temp[right]; answertemp.push_back(right); right++; if(right > arrSize){ return std::vector<int>(0); } } while(!(sum>=l && sum<=u)){ sum -= answertemp[0]; answertemp.erase(0); sum += temp[right]; answertemp.push_back(right); right++; if(right > arrSize){ return std::vector<int>(0); } } int asize = answertemp.size(); for(int i = 0; i < asize; i++){ int it = find(w.begin(), w.end(), answertemp[i]) - w.begin(); answertemp.erase(it); answer.push_back(it) } return answer; } /* if(temp[arrSize-1] - temp[0] == 1){ vector<int> smallarr; vector<int> largearr; int largeSize = 0; for(int i = 0; i < arrSize; i++){ if(m[i]==temp[n-1]){ largearr.push_back(i); largeSize++; } else{ smallarr.push_back(i); smallSize++; } } int mult = temp[0]*temp[n-1]; int modval = u%mult; int reps = u/mult; int smallmod = modval%temp[0]; int largemod = modval%temp[arrSize-1]; int smalldiv = modval/temp[0]; int largediv = modval/temp[arrSize-1]; if(smallmod==0 && smalldiv>=smallSize){ smallSize -= smalldiv; for(int i = 0; i < smalldiv; i++){ answer.push_back(smallarr[i]); smallarr.erase(i); smallSize--; } } else if(largemod==0 && largediv>=largeSize){ largeSize -= largediv; for(int i = 0; i < largediv; i++){ answer.push_back(largearr[i]); largearr.erase(i); } } } */ return std::vector<int>(0); }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:39:17: error: 'arr' was not declared in this scope
   39 |         if(temp[arr-1]-temp[0]==1){
      |                 ^~~
molecules.cpp:55:35: error: no matching function for call to 'std::vector<int>::erase(int)'
   55 |                 answertemp.erase(0);
      |                                   ^
In file included from /usr/include/c++/10/vector:67,
                 from molecules.h:3,
                 from molecules.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1430:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(std::vector<_Tp, _Alloc>::const_iterator) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::iterator = std::vector<int>::iterator; std::vector<_Tp, _Alloc>::const_iterator = std::vector<int>::const_iterator]'
 1430 |       erase(const_iterator __position)
      |       ^~~~~
/usr/include/c++/10/bits/stl_vector.h:1430:28: note:   no known conversion for argument 1 from 'int' to 'std::vector<int>::const_iterator'
 1430 |       erase(const_iterator __position)
      |             ~~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1457:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(std::vector<_Tp, _Alloc>::const_iterator, std::vector<_Tp, _Alloc>::const_iterator) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::iterator = std::vector<int>::iterator; std::vector<_Tp, _Alloc>::const_iterator = std::vector<int>::const_iterator]'
 1457 |       erase(const_iterator __first, const_iterator __last)
      |       ^~~~~
/usr/include/c++/10/bits/stl_vector.h:1457:7: note:   candidate expects 2 arguments, 1 provided
molecules.cpp:66:36: error: no matching function for call to 'std::vector<int>::erase(int&)'
   66 |                 answertemp.erase(it);
      |                                    ^
In file included from /usr/include/c++/10/vector:67,
                 from molecules.h:3,
                 from molecules.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1430:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(std::vector<_Tp, _Alloc>::const_iterator) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::iterator = std::vector<int>::iterator; std::vector<_Tp, _Alloc>::const_iterator = std::vector<int>::const_iterator]'
 1430 |       erase(const_iterator __position)
      |       ^~~~~
/usr/include/c++/10/bits/stl_vector.h:1430:28: note:   no known conversion for argument 1 from 'int' to 'std::vector<int>::const_iterator'
 1430 |       erase(const_iterator __position)
      |             ~~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1457:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(std::vector<_Tp, _Alloc>::const_iterator, std::vector<_Tp, _Alloc>::const_iterator) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::iterator = std::vector<int>::iterator; std::vector<_Tp, _Alloc>::const_iterator = std::vector<int>::const_iterator]'
 1457 |       erase(const_iterator __first, const_iterator __last)
      |       ^~~~~
/usr/include/c++/10/bits/stl_vector.h:1457:7: note:   candidate expects 2 arguments, 1 provided
molecules.cpp:67:37: error: expected ';' before '}' token
   67 |                 answer.push_back(it)
      |                                     ^
      |                                     ;
   68 |             }
      |             ~                        
molecules.cpp:40:17: warning: unused variable 'left' [-Wunused-variable]
   40 |             int left = 0;
      |                 ^~~~