Submission #351264

# Submission time Handle Problem Language Result Execution time Memory
351264 2021-01-19T18:36:30 Z denkendoemeer Palindromes (APIO14_palindrome) C++14
100 / 100
31 ms 39660 KB
#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

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 time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 0 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 304 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1644 KB Output is correct
2 Correct 1 ms 1644 KB Output is correct
3 Correct 2 ms 1644 KB Output is correct
4 Correct 2 ms 1644 KB Output is correct
5 Correct 2 ms 1644 KB Output is correct
6 Correct 2 ms 1644 KB Output is correct
7 Correct 2 ms 1644 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 1260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 13420 KB Output is correct
2 Correct 13 ms 13420 KB Output is correct
3 Correct 10 ms 13420 KB Output is correct
4 Correct 11 ms 13420 KB Output is correct
5 Correct 11 ms 13420 KB Output is correct
6 Correct 8 ms 9964 KB Output is correct
7 Correct 10 ms 11500 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 4 ms 3564 KB Output is correct
10 Correct 9 ms 11500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 39660 KB Output is correct
2 Correct 29 ms 39660 KB Output is correct
3 Correct 29 ms 39660 KB Output is correct
4 Correct 29 ms 39660 KB Output is correct
5 Correct 31 ms 39660 KB Output is correct
6 Correct 29 ms 35308 KB Output is correct
7 Correct 28 ms 33132 KB Output is correct
8 Correct 4 ms 1132 KB Output is correct
9 Correct 4 ms 1132 KB Output is correct
10 Correct 29 ms 32748 KB Output is correct
11 Correct 29 ms 39660 KB Output is correct
12 Correct 7 ms 4716 KB Output is correct