제출 #987275

#제출 시각아이디문제언어결과실행 시간메모리
987275normankr07Detecting Molecules (IOI16_molecules)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using ll = long long; #include "molecules.h" std::vector<int> find_subset(int l, int u, std::vector<int> w) { // for (int i = 1; i <= n; i++) // { // if (l <= w[i - 1] && w[i - 1] <= u) // { // return vector<int>(i); // } // } vector<pair<int, int>> ww; ll sum = 0; for (int i = 0; i < n; i++) { sum += w[i]; ww.push_back(make_pair(w[i], i)); } sort(ww.begin(), ww.end()); vector<int> id; for (int i = n - 1, j = n; i < j && i >= -1;) { while (sum > u && i >= 0) { sum -= ww[i].first; i--; } if (l <= sum && sum <= u) { for (int p = 0; p <= i; p++) id.push_back(ww[p].second); for (int p = j; p < n; p++) id.push_back(ww[p].second); return id; } j--; sum += ww[j].first; } return vector<int>(); }

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

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:14:5: error: 'vector' was not declared in this scope
   14 |     vector<pair<int, int>> ww;
      |     ^~~~~~
molecules.cpp:14:5: note: suggested alternatives:
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:389:11: note:   'std::vector'
  389 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
In file included 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/vector:86:13: note:   'std::pmr::vector'
   86 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
molecules.cpp:14:12: error: 'pair' was not declared in this scope; did you mean 'std::pair'?
   14 |     vector<pair<int, int>> ww;
      |            ^~~~
      |            std::pair
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from molecules.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: 'std::pair' declared here
  211 |     struct pair
      |            ^~~~
molecules.cpp:14:17: error: expected primary-expression before 'int'
   14 |     vector<pair<int, int>> ww;
      |                 ^~~
molecules.cpp:16:25: error: 'n' was not declared in this scope
   16 |     for (int i = 0; i < n; i++)
      |                         ^
molecules.cpp:19:9: error: 'ww' was not declared in this scope; did you mean 'w'?
   19 |         ww.push_back(make_pair(w[i], i));
      |         ^~
      |         w
molecules.cpp:19:22: error: 'make_pair' was not declared in this scope; did you mean 'std::make_pair'?
   19 |         ww.push_back(make_pair(w[i], i));
      |                      ^~~~~~~~~
      |                      std::make_pair
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from molecules.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:567:5: note: 'std::make_pair' declared here
  567 |     make_pair(_T1&& __x, _T2&& __y)
      |     ^~~~~~~~~
molecules.cpp:21:10: error: 'ww' was not declared in this scope; did you mean 'w'?
   21 |     sort(ww.begin(), ww.end());
      |          ^~
      |          w
molecules.cpp:21:5: error: 'sort' was not declared in this scope; did you mean 'std::sort'?
   21 |     sort(ww.begin(), ww.end());
      |     ^~~~
      |     std::sort
In file included 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/pstl/glue_algorithm_defs.h:296:1: note: 'std::sort' declared here
  296 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
      | ^~~~
molecules.cpp:22:12: error: expected primary-expression before 'int'
   22 |     vector<int> id;
      |            ^~~
molecules.cpp:23:18: error: 'n' was not declared in this scope
   23 |     for (int i = n - 1, j = n; i < j && i >= -1;)
      |                  ^
molecules.cpp:23:36: error: 'j' was not declared in this scope
   23 |     for (int i = n - 1, j = n; i < j && i >= -1;)
      |                                    ^
molecules.cpp:33:17: error: 'id' was not declared in this scope; did you mean 'i'?
   33 |                 id.push_back(ww[p].second);
      |                 ^~
      |                 i
molecules.cpp:35:17: error: 'id' was not declared in this scope; did you mean 'i'?
   35 |                 id.push_back(ww[p].second);
      |                 ^~
      |                 i
molecules.cpp:36:20: error: 'id' was not declared in this scope; did you mean 'i'?
   36 |             return id;
      |                    ^~
      |                    i
molecules.cpp:41:19: error: expected primary-expression before 'int'
   41 |     return vector<int>();
      |                   ^~~
molecules.cpp:41:19: error: expected ';' before 'int'
   41 |     return vector<int>();
      |                   ^~~
      |                   ;
molecules.cpp:41:22: error: expected unqualified-id before '>' token
   41 |     return vector<int>();
      |                      ^