제출 #949805

#제출 시각아이디문제언어결과실행 시간메모리
949805Rainmaker2627Detecting Molecules (IOI16_molecules)C++17
컴파일 에러
0 ms0 KiB
#include "molecules.h" std::vector<int> find_subset(int l, int u, std::vector<int> w) { long long s=0, lo=0, hi=0, n=w.size(); std::vector<pair<int, int>> t; std::vector<int> ans(0); for (int i = 0; i < n; ++i) t.emplace_back(w[i], i); sort(t.begin(), t.end()); while (lo<n) { if (s<l) { if (hi<n) s+=t[hi++].first; else break; } else if (s>u && lo<n) s-=t[lo++].first; if (l<=s && s<=u) { for (int i = lo; i < hi; ++i) ans.push_back(t[i].second); break; } } return ans; }

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

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:5:14: error: 'pair' was not declared in this scope; did you mean 'std::pair'?
    5 |  std::vector<pair<int, int>> t;
      |              ^~~~
      |              std::pair
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/vector:60,
                 from molecules.h:3,
                 from molecules.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: 'std::pair' declared here
  211 |     struct pair
      |            ^~~~
molecules.cpp:5:27: error: template argument 1 is invalid
    5 |  std::vector<pair<int, int>> t;
      |                           ^~
molecules.cpp:5:27: error: template argument 2 is invalid
molecules.cpp:7:32: error: request for member 'emplace_back' in 't', which is of non-class type 'int'
    7 |  for (int i = 0; i < n; ++i) t.emplace_back(w[i], i);
      |                                ^~~~~~~~~~~~
molecules.cpp:8:9: error: request for member 'begin' in 't', which is of non-class type 'int'
    8 |  sort(t.begin(), t.end());
      |         ^~~~~
molecules.cpp:8:20: error: request for member 'end' in 't', which is of non-class type 'int'
    8 |  sort(t.begin(), t.end());
      |                    ^~~
molecules.cpp:8:2: error: 'sort' was not declared in this scope; did you mean 'short'?
    8 |  sort(t.begin(), t.end());
      |  ^~~~
      |  short
molecules.cpp:11:18: error: invalid types 'int[long long int]' for array subscript
   11 |    if (hi<n) s+=t[hi++].first;
      |                  ^
molecules.cpp:13:31: error: invalid types 'int[long long int]' for array subscript
   13 |   } else if (s>u && lo<n) s-=t[lo++].first;
      |                               ^
molecules.cpp:15:49: error: invalid types 'int[int]' for array subscript
   15 |    for (int i = lo; i < hi; ++i) ans.push_back(t[i].second);
      |                                                 ^