Submission #351264

#TimeUsernameProblemLanguageResultExecution timeMemory
351264denkendoemeerPalindromes (APIO14_palindrome)C++14
100 / 100
31 ms39660 KiB
#include<bits/stdc++.h> #define ll long long using namespace std; int cnt[300005][30],len[300005],nex[300005],cnt2[300005],u; char s[300005]; int findnex(int nod,int p) { while(s[p]!=s[p-len[nod]-1]) nod=nex[nod]; return nod; } int update(int nod,int p) { int aux=s[p]-97; nod=findnex(nod,p); if (cnt[nod][aux]==0){ ++u; len[u]=len[nod]+2; nex[u]=cnt[findnex(nex[nod],p)][aux]; cnt[nod][aux]=u; } return cnt[nod][aux]; } int main() { //freopen(".in","r",stdin); //freopen(".out","w",stdout); fgets(s,300003,stdin); int n=strlen(s)-1; len[1]=-1; u=1; nex[0]=nex[1]=1; int cur=1,i; for(i=0;i<n;i++) cur=update(cur,i),cnt2[cur]++; ll ans=0; for(i=u;i>=0;i--) cnt2[nex[i]]=cnt2[nex[i]]+cnt2[i],ans=max(ans,1LL*cnt2[i]*len[i]); printf("%lld\n",ans); return 0; }

Compilation message (stderr)

palindrome.cpp: In function 'int main()':
palindrome.cpp:28:10: warning: ignoring return value of 'char* fgets(char*, int, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   28 |     fgets(s,300003,stdin);
      |     ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...