답안 #161135

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
161135 2019-10-31T19:14:10 Z errorgorn JOIOJI (JOI14_joioji) C++14
컴파일 오류
0 ms 0 KB
            #include <cstdio>
            #include <unordered_map>
            #include <utility>
            #include <string>
            #include <iostream>
            #include <cstring>
            #include <algorithm>
            using namespace std;
            typedef pair<int,int> ii;
            int n;
            char c;
            string s;
            class custom_hash{
    public:
        template <typename T, typename U>
        size_t operator()(const pair<T,U> &i)const{
            return std::hash<T>(i.first) ^ std::hash<U>(i.second);
        }
};
            unordered_map<ii,int,custom_hash> suffix;
            int arr[3];
            int pre[3];
            int main(){
                suffix.reserve(4096);
                suffix.max_load_factor(0.25);
                //freopen("input.txt","r",stdin);
                scanf("%d",&n);
                getchar();
                c=getchar();
                while (c!='\n'){
                    s+=c;
                    if (c=='J') arr[0]++;
                    else if (c=='O') arr[1]++;
                    else arr[2]++;
                    c=getchar();
                }
                suffix[ii(0,0)]=0;
                for (int x=0;x<3;x++) pre[x]=arr[x];
                for (int x=0;x<s.size();x++){
                    if (s[x]=='J') pre[0]--;
                    else if (s[x]=='O') pre[1]--;
                    else pre[2]--;
                    suffix[ii(pre[0]-pre[1],pre[0]-pre[2])]=x+1;
                }
                memset(pre,0,sizeof(pre));
                int ans=0;
                int a=arr[0]-arr[1],b=arr[0]-arr[2];
                for (int x=0;x<s.size();x++){
                    ans=max(ans,suffix[ii(a-(pre[0]-pre[1]),b-(pre[0]-pre[2]))]-x);
                    if (s[x]=='J') pre[0]++;
                    else if (s[x]=='O') pre[1]++;
                    else pre[2]++;
                }
                printf("%d\n",ans);
            }

Compilation message

joioji.cpp: In function 'int main()':
joioji.cpp:39:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for (int x=0;x<s.size();x++){
                              ~^~~~~~~~~
joioji.cpp:48:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for (int x=0;x<s.size();x++){
                              ~^~~~~~~~~
joioji.cpp: In instantiation of 'size_t custom_hash::operator()(const std::pair<_T1, _T2>&) const [with T = int; U = int; size_t = long unsigned int]':
/usr/include/c++/7/bits/hashtable_policy.h:1368:23:   required from 'std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _H1, _H2, std::__detail::_Default_ranged_hash, true>::__hash_code std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _H1, _H2, std::__detail::_Default_ranged_hash, true>::_M_hash_code(const _Key&) const [with _Key = std::pair<int, int>; _Value = std::pair<const std::pair<int, int>, int>; _ExtractKey = std::__detail::_Select1st; _H1 = custom_hash; _H2 = std::__detail::_Mod_range_hashing; std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _H1, _H2, std::__detail::_Default_ranged_hash, true>::__hash_code = long unsigned int]'
/usr/include/c++/7/bits/hashtable_policy.h:744:19:   required from 'std::__detail::_Map_base<_Key, _Pair, _Alloc, std::__detail::_Select1st, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits, true>::mapped_type& std::__detail::_Map_base<_Key, _Pair, _Alloc, std::__detail::_Select1st, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits, true>::operator[](std::__detail::_Map_base<_Key, _Pair, _Alloc, std::__detail::_Select1st, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits, true>::key_type&&) [with _Key = std::pair<int, int>; _Pair = std::pair<const std::pair<int, int>, int>; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >; _Equal = std::equal_to<std::pair<int, int> >; _H1 = custom_hash; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, false, true>; std::__detail::_Map_base<_Key, _Pair, _Alloc, std::__detail::_Select1st, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits, true>::mapped_type = int; std::__detail::_Map_base<_Key, _Pair, _Alloc, std::__detail::_Select1st, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits, true>::key_type = std::pair<int, int>]'
/usr/include/c++/7/bits/unordered_map.h:980:20:   required from 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::mapped_type& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::key_type&&) [with _Key = std::pair<int, int>; _Tp = int; _Hash = custom_hash; _Pred = std::equal_to<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >; std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::mapped_type = int; std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::key_type = std::pair<int, int>]'
joioji.cpp:37:31:   required from here
joioji.cpp:17:25: error: no matching function for call to 'std::hash<int>::hash(const int&)'
             return std::hash<T>(i.first) ^ std::hash<U>(i.second);
                         ^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/bits/basic_string.h:6575:0,
                 from /usr/include/c++/7/string:52,
                 from /usr/include/c++/7/stdexcept:39,
                 from /usr/include/c++/7/array:39,
                 from /usr/include/c++/7/tuple:39,
                 from /usr/include/c++/7/unordered_map:41,
                 from joioji.cpp:2:
/usr/include/c++/7/bits/functional_hash.h:148:3: note: candidate: constexpr std::hash<int>::hash()
   _Cxx_hashtable_define_trivial_hash(int)
   ^
/usr/include/c++/7/bits/functional_hash.h:148:3: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/7/bits/functional_hash.h:148:3: note: candidate: constexpr std::hash<int>::hash(const std::hash<int>&)
/usr/include/c++/7/bits/functional_hash.h:148:3: note:   no known conversion for argument 1 from 'const int' to 'const std::hash<int>&'
/usr/include/c++/7/bits/functional_hash.h:148:3: note: candidate: constexpr std::hash<int>::hash(std::hash<int>&&)
/usr/include/c++/7/bits/functional_hash.h:148:3: note:   no known conversion for argument 1 from 'const int' to 'std::hash<int>&&'
joioji.cpp:17:49: error: no matching function for call to 'std::hash<int>::hash(const int&)'
             return std::hash<T>(i.first) ^ std::hash<U>(i.second);
                                                 ^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/bits/basic_string.h:6575:0,
                 from /usr/include/c++/7/string:52,
                 from /usr/include/c++/7/stdexcept:39,
                 from /usr/include/c++/7/array:39,
                 from /usr/include/c++/7/tuple:39,
                 from /usr/include/c++/7/unordered_map:41,
                 from joioji.cpp:2:
/usr/include/c++/7/bits/functional_hash.h:148:3: note: candidate: constexpr std::hash<int>::hash()
   _Cxx_hashtable_define_trivial_hash(int)
   ^
/usr/include/c++/7/bits/functional_hash.h:148:3: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/7/bits/functional_hash.h:148:3: note: candidate: constexpr std::hash<int>::hash(const std::hash<int>&)
/usr/include/c++/7/bits/functional_hash.h:148:3: note:   no known conversion for argument 1 from 'const int' to 'const std::hash<int>&'
/usr/include/c++/7/bits/functional_hash.h:148:3: note: candidate: constexpr std::hash<int>::hash(std::hash<int>&&)
/usr/include/c++/7/bits/functional_hash.h:148:3: note:   no known conversion for argument 1 from 'const int' to 'std::hash<int>&&'
joioji.cpp:27:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
                 scanf("%d",&n);
                 ~~~~~^~~~~~~~~