Submission #106618

#TimeUsernameProblemLanguageResultExecution timeMemory
106618ekremPalindromes (APIO14_palindrome)C++98
0 / 100
1079 ms31480 KiB
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define N 1000005
using namespace std;

typedef long long ll;
typedef pair < int , int > ii;

int n, k, son, sa[N], l[N], p[20][N];
ll ans;
ii q[N];
pair < ii , int > x[N];
char s[N];

int lcp(int x, int y){
	int ans = 0;
	for(int i = k; i >= 0; i--)
		if(p[i][x] == p[i][y]){
			x += (1<<i);
			y += (1<<i);
			ans += (1<<i);
		}
	return ans;
}

void ekle(int x){
	while(son){
		if(q[son].st > l[x])
			son--;
		else
			break;
	}
	q[++son] = mp(l[x], x);
}

bool palmi(int bas, int son){
	for(int i = bas; i <= son; i++)
		if(s[i] != s[son - i + 1])
			return 0;
	return 1;
}

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%s",s + 1);
	n = strlen(s + 1);
	for(int i = 1; i <= n; i++)
		p[0][i] = s[i] - 'a' + 1;
	for(k = 1; (1<<k) <= n+n; k++){
		for(int i = 1; i <= n; i++)
			x[i] = mp(mp(p[k - 1][i], p[k - 1][i + (1<<(k - 1))]), i);
		sort(x + 1, x + n + 1);
		for(int i = 1; i <= n; i++)
			p[k][x[i].nd] = p[k][x[i - 1].nd] + (x[i].st != x[i - 1].st);
	}k--;
	for(int i = 1; i <= n; i++)
		sa[p[k][i]] = i;
	for(int i = 1; i <= n; i++){
		l[i] = lcp(sa[i - 1], sa[i]);
		// cout << l[i] << " -> ";
		// printf("%s\n", s + sa[i]);
	}
	for(int i = 1; i <= n; i++){
		int bas = sa[i] + l[i + 1];
		ekle(i);
		// cout << i << " " << bas << endl;
		for(int j = bas; j <= n; j++)
			if(palmi(sa[i], j)){
				int uz = j - sa[i] + 1;
				int ind = lower_bound(q + 1, q + son + 1, mp(uz, 0)) - q;
				int kac;
				if(ind > son)
					kac = 1;
				else
					kac = i - q[ind].nd + 2;
				ans = max(ans, 1ll*uz*kac);
				// cout << i << " (" << sa[i] << ", " << j << ") " << ind << " " << q[ind].nd << " " << kac << endl;
			}
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message (stderr)

palindrome.cpp: In function 'int main()':
palindrome.cpp:50:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",s + 1);
  ~~~~~^~~~~~~~~~~~
#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...