제출 #956142

#제출 시각아이디문제언어결과실행 시간메모리
956142manishjha91Detecting Molecules (IOI16_molecules)C++17
컴파일 에러
0 ms0 KiB
#pragma once #include <vector> std::vector<int> find_subset(int l, int u, std::vector<int> w) { std::vector<pair<int,int>> curr; for(int i=0; i<w.size(); i++) { curr.push_back({w[i],i}); } sort(curr.begin(),curr.end()); long long sum = 0; bool found = 0; int low = 0; int hi = 0; for(; hi<curr.size(); hi++) { sum+=curr[hi].first; while(sum>u) { sum-=curr[low++].first; } if(sum>=l) { found = 1; break; } } if(!found) return std::vector<int>(0); std::vector<int> res; for(int i=low; i<=hi; i++) { res.push_back(curr[i].second); } sort(res.begin(),res.end()); return res; }

컴파일 시 표준 에러 (stderr) 메시지

molecules.cpp:2:9: warning: #pragma once in main file
    2 | #pragma once
      |         ^~~~
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:8:14: error: 'pair' was not declared in this scope; did you mean 'std::pair'?
    8 |  std::vector<pair<int,int>> curr;
      |              ^~~~
      |              std::pair
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/vector:60,
                 from molecules.cpp:4:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: 'std::pair' declared here
  211 |     struct pair
      |            ^~~~
molecules.cpp:8:26: error: template argument 1 is invalid
    8 |  std::vector<pair<int,int>> curr;
      |                          ^~
molecules.cpp:8:26: error: template argument 2 is invalid
molecules.cpp:10:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  for(int i=0; i<w.size(); i++)
      |               ~^~~~~~~~~
molecules.cpp:12:8: error: request for member 'push_back' in 'curr', which is of non-class type 'int'
   12 |   curr.push_back({w[i],i});
      |        ^~~~~~~~~
molecules.cpp:15:12: error: request for member 'begin' in 'curr', which is of non-class type 'int'
   15 |  sort(curr.begin(),curr.end());
      |            ^~~~~
molecules.cpp:15:25: error: request for member 'end' in 'curr', which is of non-class type 'int'
   15 |  sort(curr.begin(),curr.end());
      |                         ^~~
molecules.cpp:15:2: error: 'sort' was not declared in this scope; did you mean 'short'?
   15 |  sort(curr.begin(),curr.end());
      |  ^~~~
      |  short
molecules.cpp:21:16: error: request for member 'size' in 'curr', which is of non-class type 'int'
   21 |  for(; hi<curr.size(); hi++)
      |                ^~~~
molecules.cpp:23:12: error: invalid types 'int[int]' for array subscript
   23 |   sum+=curr[hi].first;
      |            ^
molecules.cpp:27:13: error: invalid types 'int[int]' for array subscript
   27 |    sum-=curr[low++].first;
      |             ^
molecules.cpp:43:21: error: invalid types 'int[int]' for array subscript
   43 |   res.push_back(curr[i].second);
      |                     ^