제출 #430481

#제출 시각아이디문제언어결과실행 시간메모리
430481MamedovDetecting Molecules (IOI16_molecules)C++17
컴파일 에러
0 ms0 KiB
#include "molecules.h" #include <memory.h> #include <cstdlib> #include <iostream> #include <algorithm> #include <vector> #define maxx 200005 using namespace std; typedef long long ll; struct data{ ll w; int idx; }; data p[maxx]; bool cmp(data a, data b){ return a.w < b.w; } std::vector<int> find_subset(int l, int u, std::vector<int> weight){ vector<int>res; res.clear(); int n = weight.size(); for(int i = 0; i < n; i++){ p[i].w = 1LL * weight[i]; p[i].idx = i; } sort(p, p + n, cmp); ll sum = 0; int ptr1 = 0, ptr2 = 0; while(ptr1 < n){ while(ptr2 < n && sum < 1LL * l){ sum += p[ptr2].w; ptr2++; } if(sum >= 1LL * l && sum <= 1LL * u){ for(int i = ptr1; i < ptr2; i++){ res.push_back(p[i].idx); } return res; } else{ while(ptr1 < n && sum > 1LL * u){ sum -= p[ptr1].w; ptr1++; } } if(ptr2 == n && sum < 1LL * l) break; } return res; }

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

molecules.cpp:16:1: error: reference to 'data' is ambiguous
   16 | data p[maxx];
      | ^~~~
In file included from /usr/include/c++/10/vector:69,
                 from molecules.h:3,
                 from molecules.cpp:1:
/usr/include/c++/10/bits/range_access.h:319:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  319 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:310:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  310 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:300:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  300 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:290:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  290 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
molecules.cpp:12:8: note:                 'struct data'
   12 | struct data{
      |        ^~~~
molecules.cpp:18:10: error: reference to 'data' is ambiguous
   18 | bool cmp(data a, data b){
      |          ^~~~
In file included from /usr/include/c++/10/vector:69,
                 from molecules.h:3,
                 from molecules.cpp:1:
/usr/include/c++/10/bits/range_access.h:319:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  319 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:310:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  310 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:300:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  300 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:290:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  290 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
molecules.cpp:12:8: note:                 'struct data'
   12 | struct data{
      |        ^~~~
molecules.cpp:18:18: error: reference to 'data' is ambiguous
   18 | bool cmp(data a, data b){
      |                  ^~~~
In file included from /usr/include/c++/10/vector:69,
                 from molecules.h:3,
                 from molecules.cpp:1:
/usr/include/c++/10/bits/range_access.h:319:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  319 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:310:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  310 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:300:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  300 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:290:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  290 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
molecules.cpp:12:8: note:                 'struct data'
   12 | struct data{
      |        ^~~~
molecules.cpp:18:24: error: expression list treated as compound expression in initializer [-fpermissive]
   18 | bool cmp(data a, data b){
      |                        ^
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:28:9: error: 'p' was not declared in this scope
   28 |         p[i].w = 1LL * weight[i];
      |         ^
molecules.cpp:31:10: error: 'p' was not declared in this scope
   31 |     sort(p, p + n, cmp);
      |          ^