Submission #220975

# Submission time Handle Problem Language Result Execution time Memory
220975 2020-04-09T11:20:11 Z nafis_shifat Palindromes (APIO14_palindrome) C++14
100 / 100
34 ms 36224 KB
#include<bits/stdc++.h>
#define pii pair<int,int>
#define ll long long
using namespace std;
const int mxn=3e5+6;

int tree[mxn][26];
int idx;
int len[mxn];
int link[mxn],t;

char s[mxn];


ll oc[mxn]={};

void init()
{
	len[1]=-1;
    len[2]=0;

    link[1]=link[2]=1;
    idx=t=2;

}
void extend(int p)
{

	while(s[p-len[t]-1]!=s[p])t=link[t];

	int x=link[t];
	int c=s[p]-'a';
    
    while(s[p-len[x]-1]!=s[p])x=link[x];


    if(!tree[t][c])
    {
    	tree[t][c]=++idx;
    	len[idx]=len[t]+2;

    	link[idx]= len[idx]==1 ? 2 : tree[x][c];
    }

    t=tree[t][c];
    oc[t]++;
  
}

 
int main()
{
    init();
	scanf("%s",s+1);



	int n=strlen(s+1);

	for(int i=1;i<=n;i++)extend(i);
	ll res=0;
	for(int i=idx;i>2;i--)
	{
		res=max(res,len[i]*oc[i]);
		oc[link[i]]+=oc[i];
	}
	cout<<res<<endl;

	return 0;
}

Compilation message

palindrome.cpp: In function 'int main()':
palindrome.cpp:54:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",s+1);
  ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1536 KB Output is correct
2 Correct 5 ms 1536 KB Output is correct
3 Correct 6 ms 1536 KB Output is correct
4 Correct 5 ms 1536 KB Output is correct
5 Correct 6 ms 1536 KB Output is correct
6 Correct 5 ms 1536 KB Output is correct
7 Correct 5 ms 1536 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12160 KB Output is correct
2 Correct 14 ms 12160 KB Output is correct
3 Correct 14 ms 12160 KB Output is correct
4 Correct 14 ms 12160 KB Output is correct
5 Correct 14 ms 12160 KB Output is correct
6 Correct 11 ms 8960 KB Output is correct
7 Correct 13 ms 10496 KB Output is correct
8 Correct 7 ms 640 KB Output is correct
9 Correct 8 ms 3328 KB Output is correct
10 Correct 13 ms 10496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 35840 KB Output is correct
2 Correct 32 ms 35832 KB Output is correct
3 Correct 33 ms 36088 KB Output is correct
4 Correct 33 ms 36216 KB Output is correct
5 Correct 34 ms 36224 KB Output is correct
6 Correct 30 ms 32256 KB Output is correct
7 Correct 29 ms 30200 KB Output is correct
8 Correct 10 ms 1152 KB Output is correct
9 Correct 10 ms 1152 KB Output is correct
10 Correct 29 ms 29820 KB Output is correct
11 Correct 32 ms 36088 KB Output is correct
12 Correct 12 ms 4352 KB Output is correct