Submission #250230

# Submission time Handle Problem Language Result Execution time Memory
250230 2020-07-17T09:00:12 Z errorgorn Palindromes (APIO14_palindrome) C++14
100 / 100
32 ms 35080 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ll,ii>
#define endl '\n'

int edges[300005][26];
int backedge[300005];
int len[300005];

int PREV=0;
int INDEX=1;

int cnt[300005];

string s;
int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
	
	cin>>s;
	
	memset(edges,-1,sizeof(edges));
	backedge[0]=0,backedge[1]=0;
	len[0]=-1,len[1]=0;
	
	for (int x=0;x<s.size();x++){
		while (s[x-len[PREV]-1]!=s[x]) PREV=backedge[PREV];
		
		if (edges[PREV][s[x]-'a']==-1) edges[PREV][s[x]-'a']=++INDEX;
		int curr=edges[PREV][s[x]-'a'];
		len[curr]=len[PREV]+2;
		
		if (len[curr]==1){
			backedge[curr]=1;
		}
		else{
			int b=backedge[PREV];
			while (s[x-len[b]-1]!=s[x]) b=backedge[b];
			backedge[curr]=edges[b][s[x]-'a'];
		}
		
		PREV=curr;
		
		cnt[curr]++;
		//cout<<curr<<endl;
	}
	
	ll best=0;
	
	for (int x=INDEX;x>1;x--){
		best=max(best,(ll)cnt[x]*len[x]);
		cnt[backedge[x]]+=cnt[x];
	}
	
	cout<<best<<endl;
}

Compilation message

palindrome.cpp: In function 'int main()':
palindrome.cpp:28:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int x=0;x<s.size();x++){
               ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 16 ms 30848 KB Output is correct
2 Correct 15 ms 30848 KB Output is correct
3 Correct 16 ms 30848 KB Output is correct
4 Correct 16 ms 30848 KB Output is correct
5 Correct 16 ms 30848 KB Output is correct
6 Correct 20 ms 30840 KB Output is correct
7 Correct 16 ms 30848 KB Output is correct
8 Correct 16 ms 30848 KB Output is correct
9 Correct 18 ms 30848 KB Output is correct
10 Correct 17 ms 30924 KB Output is correct
11 Correct 16 ms 30848 KB Output is correct
12 Correct 16 ms 30848 KB Output is correct
13 Correct 16 ms 30848 KB Output is correct
14 Correct 16 ms 30848 KB Output is correct
15 Correct 16 ms 30856 KB Output is correct
16 Correct 22 ms 30848 KB Output is correct
17 Correct 16 ms 30848 KB Output is correct
18 Correct 16 ms 30936 KB Output is correct
19 Correct 16 ms 30848 KB Output is correct
20 Correct 16 ms 30848 KB Output is correct
21 Correct 16 ms 30848 KB Output is correct
22 Correct 16 ms 30848 KB Output is correct
23 Correct 16 ms 30848 KB Output is correct
24 Correct 16 ms 30976 KB Output is correct
25 Correct 16 ms 30848 KB Output is correct
26 Correct 16 ms 30848 KB Output is correct
27 Correct 16 ms 30848 KB Output is correct
28 Correct 16 ms 30848 KB Output is correct
29 Correct 16 ms 30848 KB Output is correct
30 Correct 18 ms 30848 KB Output is correct
31 Correct 16 ms 30848 KB Output is correct
32 Correct 16 ms 30848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 30848 KB Output is correct
2 Correct 16 ms 30848 KB Output is correct
3 Correct 17 ms 30848 KB Output is correct
4 Correct 19 ms 30856 KB Output is correct
5 Correct 16 ms 30848 KB Output is correct
6 Correct 16 ms 30848 KB Output is correct
7 Correct 16 ms 30848 KB Output is correct
8 Correct 16 ms 30848 KB Output is correct
9 Correct 16 ms 30848 KB Output is correct
10 Correct 16 ms 30848 KB Output is correct
11 Correct 16 ms 30848 KB Output is correct
12 Correct 16 ms 30848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 30976 KB Output is correct
2 Correct 17 ms 30976 KB Output is correct
3 Correct 19 ms 31120 KB Output is correct
4 Correct 17 ms 30976 KB Output is correct
5 Correct 17 ms 30976 KB Output is correct
6 Correct 17 ms 30976 KB Output is correct
7 Correct 16 ms 30976 KB Output is correct
8 Correct 22 ms 30976 KB Output is correct
9 Correct 16 ms 30976 KB Output is correct
10 Correct 16 ms 30976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 32384 KB Output is correct
2 Correct 20 ms 32384 KB Output is correct
3 Correct 22 ms 32384 KB Output is correct
4 Correct 20 ms 32384 KB Output is correct
5 Correct 20 ms 32384 KB Output is correct
6 Correct 19 ms 32000 KB Output is correct
7 Correct 19 ms 32164 KB Output is correct
8 Correct 19 ms 31232 KB Output is correct
9 Correct 18 ms 31488 KB Output is correct
10 Correct 18 ms 32128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 35068 KB Output is correct
2 Correct 27 ms 35080 KB Output is correct
3 Correct 26 ms 35072 KB Output is correct
4 Correct 28 ms 35080 KB Output is correct
5 Correct 25 ms 35072 KB Output is correct
6 Correct 26 ms 34696 KB Output is correct
7 Correct 27 ms 34560 KB Output is correct
8 Correct 22 ms 31668 KB Output is correct
9 Correct 22 ms 31620 KB Output is correct
10 Correct 24 ms 34440 KB Output is correct
11 Correct 32 ms 35080 KB Output is correct
12 Correct 22 ms 32008 KB Output is correct