제출 #900089

#제출 시각아이디문제언어결과실행 시간메모리
900089mannshah1211Detecting Molecules (IOI16_molecules)C++14
컴파일 에러
0 ms0 KiB
#include "molecules.h" std::vector<int> find_subset(int l, int u, std::vector<int> w) { if (std::accumulate(w.begin(), w.end(), 0LL) < l) { return {}; } std::vector<std::pair<int, int>> indices; for (int i = 0; i < w.size(); i++) { indices.push_back(std::make_pair(w[i], i)); } if (indices[0].first > u) { return {}; } sort(indices.begin(), indices.end()); int cursum = 0, longest = 0; for (int i = 0; i < indices.size(); i++) { cursum += indices[i].first; if (cursum >= l) { cursum -= indices[i].first, longest = i; break; } } for (int i = longest; i < indices.size(); i++) { cursum += indices[i].first; cursum -= indices[i - longest].first; if (cursum >= l && cursum <= u) { std::vector<int> answer; for (int j = i; j >= i - longest + 1; j--) { answer.push_back(indices[j].second); } return answer; } } return {}; }

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

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:4:13: error: 'accumulate' is not a member of 'std'
    4 |    if (std::accumulate(w.begin(), w.end(), 0LL) < l) {
      |             ^~~~~~~~~~
molecules.cpp:8:23: 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:14:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   14 |     sort(indices.begin(), indices.end());
      |     ^~~~
      |     short
molecules.cpp:16:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for (int i = 0; i < indices.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~~
molecules.cpp:23:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for (int i = longest; i < indices.size(); i++) {
      |                           ~~^~~~~~~~~~~~~~~~