제출 #1177508

#제출 시각아이디문제언어결과실행 시간메모리
1177508PAndaSSails (IOI07_sails)C++20
컴파일 에러
0 ms0 KiB
#include<iostream>
#include<set>
#include<vector>
#include<map>

using namespace std;
class cmp {
public:
    bool operator()(pair<int,int> a, pair<int,int> b){
        return ((a.first != b.first)?(a.first < b.first):(a.second > b.second));
    }
};

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n; cin >> n;
    int max_h = 0;
    vector<int> hs(n), ks(n);
    for(int i = 0; i < n; i++){
        cin >> hs[i] >> ks[i];
        max_h = max(max_h, hs[i]);
    }
    set<pair<int, int>, cmp> ord;
    for(int i = 0; i < max_h; i++){
        ord.insert(pair<int, int>(0, i));
    }
    int ans = 0;
    map<int, bool> occ;
    for(int i = n - 1; i >= 0; i--){
        occ.clear();
        while(ks[i]){
            for(auto p = ord.begin(); p != ord.end() && ks[i]; p++){
                if((*p).second < hs[i] && !occ[(*p).second]){
                    ks[i]--;
                    ans += (*p).first;
                    occ[(*p).second] = true;
                    ord.insert(pair<int, int>((*p).first + 1, ((*p).second)));
                    ord.erase(p);
                    break;
                }
            }
        }
    }
    cout << ans;
    return 0;
}

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

In file included from /usr/include/c++/11/set:60,
                 from sails.cpp:2:
/usr/include/c++/11/bits/stl_tree.h: In instantiation of 'static const _Key& std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_S_key(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Const_Link_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>::_Const_Link_type = const std::_Rb_tree_node<std::pair<int, int> >*]':
/usr/include/c++/11/bits/stl_tree.h:2071:47:   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>]'
/usr/include/c++/11/bits/stl_tree.h:2124:4:   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> >]'
/usr/include/c++/11/bits/stl_set.h:521:25:   required from 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::value_type&&) [with _Key = std::pair<int, int>; _Compare = cmp; _Alloc = std::allocator<std::pair<int, int> >; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, cmp, std::allocator<std::pair<int, int> > >::const_iterator; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other = std::allocator<std::pair<int, int> >; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key> = __gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::rebind<std::pair<int, int> >; typename _Alloc::value_type = std::pair<int, int>; std::set<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>]'
sails.cpp:25:19:   required from here
/usr/include/c++/11/bits/stl_tree.h:770:15: error: static assertion failed: comparison object must be invocable as const
  770 |               is_invocable_v<const _Compare&, const _Key&, const _Key&>,
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/11/bits/stl_tree.h:770:15: note: 'std::is_invocable_v<const cmp&, const std::pair<int, int>&, const std::pair<int, int>&>' evaluates to false