namyun1012   1년 전

안녕하세요 2108번 문제를 풀다가 제가 vscode에서 gcc로 컴파일을 할 때는 일단을 결과가 정상적으로 나오는데 백준에 넣었을 때는 컴파일 에러라고 나와서 질문을 올립니다.

required from ‘std::pair<std::_Rb_tree_node_base*, std::_Rb_tree_node_base*> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_get_insert_unique_pos(const key_type&) [with _Key = std::pair<int, int>; _Val = std::pair<int, int>; _KeyOfValue = std::_Identity<std::pair<int, int> >; _Compare = cmp; _Alloc = std::allocator<std::pair<int, int> >; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::key_type = std::pair<int, int>]’

required from ‘std::pair<std::_Rb_tree_iterator<_Val>, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(_Arg&&) [with _Arg = std::pair<int, int>; _Key = std::pair<int, int>; _Val = std::pair<int, int>; _KeyOfValue = std::_Identity<std::pair<int, int> >; _Compare = cmp; _Alloc = std::allocator<std::pair<int, int> >]’

에러로는 이런 것들이 여러가지 나오는데 아마도 제가 최빈값을 구하기 위해서 set<pair<int, int>> 를 사용하고 그곳에서 비교함수 cmp를 만드는 과정에서 문제가 생긴 것 같습니다.

어떤 것이 문제인지 알려주시면 정말 감사하겠습니다.

djm03178   1년 전

정확한 규칙은 모르겠으나, 아래와 같이 중괄호 전에 const를 넣어주면 동작합니다.

namyun1012   1년 전

감사합니다 그래도 시간 초과에 바로 걸리네요 알고리즘을 다시 생각해 봐야 할 것 같습니다

댓글을 작성하려면 로그인해야 합니다.