Submission #168063

#TimeUsernameProblemLanguageResultExecution timeMemory
168063HungAnhGoldIBO2020Palindromes (APIO14_palindrome)C++14
Compilation error
0 ms0 KiB
/* abacaba */ #include<bits/stdc++.h> #define int long long using namespace std; const int N=3e5+2; const int mod=1e9+9; const int base=79; int hash[N],rev_hash[N],mul[N],max1=0,sum[N]; map<int,int> cnt; int gethash(int l,int r){ return ((hash[r]-hash[l-1]*mul[r-l+1])%mod+mod)%mod; } int gethash_rev(int l,int r){ return ((rev_hash[l]-rev_hash[r+1]*mul[r-l+1])%mod+mod)%mod; } struct node{ int nxt[26],len,suf; }; node Eer[N]; int sz=0,lst; string s; void add(int idx){ // cout<<idx<<" BEGIN"<<endl; //special case idx=0 int cha=(s[idx]-'a'); if(idx==0){ sz++; Eer[1].nxt[cha]=sz; Eer[sz].len=1; Eer[sz].suf=2; return; } while(idx-Eer[lst].len-1<=0||s[idx]!=s[idx-Eer[lst].len-1]){ if(lst==1){ break; } lst=Eer[lst].suf; } if(!Eer[lst].nxt[cha]){ sz++; Eer[lst].nxt[cha]=sz; Eer[sz].len=Eer[lst].len+2; if(Eer[sz].len!=1){ int sf=Eer[lst].suf; assert(idx-Eer[sf].len-1>0); while(s[idx]!=s[idx-Eer[sf].len-1]){ sf=Eer[sf].suf; } Eer[sz].suf=Eer[sf].nxt[cha]; } else{ Eer[sz].suf=2; } } lst=Eer[lst].nxt[cha]; // cout<<"LST "<<lst<<" LEN "<<Eer[lst].len<<" SUF "<<Eer[sz].suf<<endl; // cout<<"END"<<endl; return; } void build(string s1){ sz=2; Eer[1].len=-1; Eer[1].suf=1; Eer[2].len=0; Eer[2].suf=1; lst=1; s=s1; for(int i=0;i<s.size();i++){ add(i); } } void dfs(int x,int val){ sum[x]=cnt[val]; for(int i=0;i<26;i++){ if(Eer[x].nxt[i]){ if(Eer[x].len==-1){ dfs(Eer[x].nxt[i],i+1); } else{ dfs(Eer[x].nxt[i],(i+1 + val*base + (i+1)*mul[Eer[x].len+1])%mod); } sum[x]+=sum[Eer[x].nxt[i]]; } } max1=max(max1,Eer[x].len*sum[x]); } signed main(){ ios::sync_with_stdio(0); cin.tie(0); string s1; cin>>s1; build(s1); int n=s1.size(),i,j,k,l,z; s1=" "+s1; mul[0]=1; for(i=1;i<=n;i++){ hash[i]=(hash[i-1]*base+(s1[i]-'a'+1))%mod; mul[i]=(mul[i-1]*base)%mod; } for(i=n;i>0;i--){ rev_hash[i]=(rev_hash[i+1]*base+(s1[i]-'a'+1))%mod; } for(i=1;i<=n;i++){ k=0; l=min(i-1,n-i); while(k<l){ j=(k+l+1)>>1; if(gethash(i-j,i+j)==gethash_rev(i-j,i+j)){ k=j; } else{ l=j-1; } } cnt[gethash(i-k,i+k)]++; if(i<=n&&s1[i]==s1[i+1]){ k=0; l=min(i-1,n-i-1); while(k<l){ j=(k+l)/2; if(gethash(i-j,i+1+j)==gethash_rev(i-j,i+1+j)){ k=j; } else{ l=j-1; } } cnt[gethash(i-k,i+1+k)]++; } } dfs(1,0); dfs(2,0); for(i=1;i<=n;i++){ if(gethash(1,i)==gethash_rev(1,i)){ max1=max(max1,i); } } cout<<max1; }

Compilation message (stderr)

palindrome.cpp: In function 'long long int gethash(long long int, long long int)':
palindrome.cpp:13:11: error: reference to 'hash' is ambiguous
  return ((hash[r]-hash[l-1]*mul[r-l+1])%mod+mod)%mod;
           ^~~~
palindrome.cpp:10:5: note: candidates are: long long int hash [300002]
 int hash[N],rev_hash[N],mul[N],max1=0,sum[N];
     ^~~~
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/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 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:4:
/usr/include/c++/7/bits/functional_hash.h:58:12: note:                 template<class _Tp> struct std::hash
     struct hash;
            ^~~~
palindrome.cpp:13:19: error: reference to 'hash' is ambiguous
  return ((hash[r]-hash[l-1]*mul[r-l+1])%mod+mod)%mod;
                   ^~~~
palindrome.cpp:10:5: note: candidates are: long long int hash [300002]
 int hash[N],rev_hash[N],mul[N],max1=0,sum[N];
     ^~~~
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/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 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:4:
/usr/include/c++/7/bits/functional_hash.h:58:12: note:                 template<class _Tp> struct std::hash
     struct hash;
            ^~~~
palindrome.cpp: In function 'void build(std::__cxx11::string)':
palindrome.cpp:70:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<s.size();i++){
              ~^~~~~~~~~
palindrome.cpp: In function 'int main()':
palindrome.cpp:99:3: error: reference to 'hash' is ambiguous
   hash[i]=(hash[i-1]*base+(s1[i]-'a'+1))%mod;
   ^~~~
palindrome.cpp:10:5: note: candidates are: long long int hash [300002]
 int hash[N],rev_hash[N],mul[N],max1=0,sum[N];
     ^~~~
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/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 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:4:
/usr/include/c++/7/bits/functional_hash.h:58:12: note:                 template<class _Tp> struct std::hash
     struct hash;
            ^~~~
palindrome.cpp:99:12: error: reference to 'hash' is ambiguous
   hash[i]=(hash[i-1]*base+(s1[i]-'a'+1))%mod;
            ^~~~
palindrome.cpp:10:5: note: candidates are: long long int hash [300002]
 int hash[N],rev_hash[N],mul[N],max1=0,sum[N];
     ^~~~
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/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 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:4:
/usr/include/c++/7/bits/functional_hash.h:58:12: note:                 template<class _Tp> struct std::hash
     struct hash;
            ^~~~
palindrome.cpp:95:26: warning: unused variable 'z' [-Wunused-variable]
  int n=s1.size(),i,j,k,l,z;
                          ^