#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
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 time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
356 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
512 KB |
Output is correct |
2 |
Incorrect |
7 ms |
512 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
1280 KB |
Output is correct |
2 |
Execution timed out |
1069 ms |
1280 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1072 ms |
10004 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1079 ms |
31480 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |