Submission #140050

#TimeUsernameProblemLanguageResultExecution timeMemory
140050shamimjucsePalindromes (APIO14_palindrome)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std;

const int mx = 100005;
struct Node
{
    int len,link,next[26];
};
string s;
Node tr[mx];
int node; /// node 1 - root with len -1, node 2 - root with len 0
int suff; /// max suffix palindrome
inline int New()
{
    node++;
    tr[node].len = 0, tr[node].link = 0;
    memset(tr[node].next, 0, sizeof tr[node].next);
    return node;
}
int cnt[mx];
inline bool Insert(int pos)
{
    int cur = suff, curlen = 0;
    int c = s[pos]-'a'; ///check it
    while(true) ///Finding maximum length palindromic suffix
    {
        curlen = tr[cur].len;
        if (pos-1-curlen>=0 && s[pos-1-curlen]==s[pos])
            break;
        cur = tr[cur].link;
    }
    if(tr[cur].next[c]) ///Existing node
    {
        suff = tr[cur].next[c];
        return false;
    }

    suff = New();
    tr[node].len = tr[cur].len + 2;
    tr[cur].next[c] = node;
    if(tr[node].len == 1) ///Single character, connected with root
    {
        tr[node].link = 2;
        cnt[node] = 1;
        return true;
    }
    while(true)///Finding suffix link
    {
        cur = tr[cur].link;
        curlen = tr[cur].len;
        if(pos-1-curlen>=0 && s[pos-1-curlen]==s[pos])
        {
            tr[node].link = tr[cur].next[c];
            cnt[node] = 1;
            break;
        }
    }
    return true;
}
void initTree()
{
    node = 2, suff = 2;
    tr[1].len = -1, tr[1].link = 1;
    tr[2].len = 0, tr[2].link = 1;
    memset(tr[1].next,0,sizeof tr[1].next);
    memset(tr[2].next,0,sizeof tr[2].next);
}
void buildTree()
{
    initTree();
    for(int i=0;i<s.size();i++)
    {
        Insert(i);
    }
}
long long sm = 0;
void count()
{
    for(int i=node;i>2;i--)
    {
        cnt[tr[i].link]+=cnt[i];
        sm = max(sm,cnt[i]*tr[i].len);
    }
}
int main()
{
    cin >> s;
    buildTree();
    count();
    cout << sm << endl;
    return 0;
}

Compilation message (stderr)

palindrome.cpp: In function 'void buildTree()':
palindrome.cpp:71:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<s.size();i++)
                 ~^~~~~~~~~
palindrome.cpp: In function 'void count()':
palindrome.cpp:82:37: error: no matching function for call to 'max(long long int&, int)'
         sm = max(sm,cnt[i]*tr[i].len);
                                     ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from palindrome.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
palindrome.cpp:82:37: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
         sm = max(sm,cnt[i]*tr[i].len);
                                     ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from palindrome.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
palindrome.cpp:82:37: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
         sm = max(sm,cnt[i]*tr[i].len);
                                     ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from palindrome.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3462:5: note: candidate: template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
palindrome.cpp:82:37: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
         sm = max(sm,cnt[i]*tr[i].len);
                                     ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from palindrome.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3468:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
palindrome.cpp:82:37: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
         sm = max(sm,cnt[i]*tr[i].len);
                                     ^