#include <bits/stdc++.h>
#define int long long
using namespace std;
int maxx=1e9;
int pierw[2]={2137,601};
int mod[2]={maxx+7,maxx+9};
int potegi[400000][2];
int hasze[400000][2];
int dl[400000];
bool odw[400000];
int licze[400000];
int essa[800000];
int ktory=1;
map<pair<int,int>,int> mapka;
vector<int> Q[400000];
pair<int,int> licz(int x,int y)
{
int hasz1=(hasze[y][0]-hasze[x-1][0]*potegi[y-x+1][0]+mod[0]*mod[0])%mod[0];
int hasz2=(hasze[y][1]-hasze[x-1][1]*potegi[y-x+1][1]+mod[1]*mod[1])%mod[1];
return {hasz1,hasz2};
}
int szukaj(pair<int,int> hasze,int x,int y)
{
if(mapka.find(hasze)!=mapka.end())
return mapka[hasze];
mapka[hasze]=ktory;
dl[ktory]=y-x+1;
ktory++;
return ktory-1;
}
int dfs(int x)
{
if(odw[x])
return licze[x];
odw[x]=1;
for(int i=0;i<Q[x].size();i++)
licze[x]+=dfs(Q[x][i]);
return licze[x];
}
void reku(int x,int y)
{
pair<int,int> hasz=licz(x,y);
int ktory=szukaj(hasz,x,y);
if(odw[ktory] || x+1>y-1)
return;
odw[ktory]=1;
pair<int,int> hasz2=licz(x+1,y-1);
int ktory2=szukaj(hasz2,x+1,y-1);
Q[ktory2].push_back(ktory);
reku(x+1,y-1);
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s;
cin>>s;
potegi[0][0]=1;
potegi[0][1]=1;
for(int i=1;i<=s.length();i++)
for(int j=0;j<2;j++)
potegi[i][j]=(potegi[i-1][j]*pierw[j])%mod[j];
for(int i=0;i<s.length();i++)
for(int j=0;j<2;j++)
{
if(i!=0)
hasze[i][j]=(hasze[i-1][j]*pierw[j]+(s[i]-'a'+1))%mod[j];
else hasze[i][j]=(s[i]-'a'+1);
}
vector<char> pomoc;
pomoc.push_back(s[0]);
for(int i=1;i<s.length();i++)
pomoc.push_back('.'),pomoc.push_back(s[i]);
int n=s.length();
int r=-1;
int k=-1;
for(int i=0;i<2*n-1;i++)
{
if(i<=r)
essa[i]=min(essa[2*k-i],r-i);
while(i-essa[i]-1>=0 && i+essa[i]+1<2*n-1 && pomoc[i-essa[i]-1]==pomoc[i+essa[i]+1])
essa[i]++;
if(r<i+essa[i])
r=i+essa[i],k=i;
int dl,x,y;
if(i%2==1)
{
dl=(essa[i]+1)/2;
x=i/2-dl+1;
y=i/2+dl;
}
else{
dl=essa[i]/2;
x=i/2-dl;
y=i/2+dl;
}
if(x>y)
continue;
pair<int,int> hasz=licz(x,y);
licze[szukaj(hasz,x,y)]++;
reku(x,y);
}
for(int i=0;i<=ktory;i++)
odw[i]=0;
int wynik=0;
for(int i=1;i<ktory;i++)
wynik=max(wynik,dl[i]*dfs(i));
cout<<wynik;
return 0;
}
Compilation message
palindrome.cpp: In function 'long long int dfs(long long int)':
palindrome.cpp:36:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(int i=0;i<Q[x].size();i++)
| ~^~~~~~~~~~~~
palindrome.cpp: In function 'int32_t main()':
palindrome.cpp:61:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for(int i=1;i<=s.length();i++)
| ~^~~~~~~~~~~~
palindrome.cpp:64:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int i=0;i<s.length();i++)
| ~^~~~~~~~~~~
palindrome.cpp:73:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for(int i=1;i<s.length();i++)
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
19088 KB |
Output is correct |
2 |
Correct |
3 ms |
19024 KB |
Output is correct |
3 |
Correct |
4 ms |
19024 KB |
Output is correct |
4 |
Correct |
4 ms |
19024 KB |
Output is correct |
5 |
Correct |
4 ms |
19024 KB |
Output is correct |
6 |
Correct |
4 ms |
19024 KB |
Output is correct |
7 |
Correct |
3 ms |
19024 KB |
Output is correct |
8 |
Correct |
4 ms |
19024 KB |
Output is correct |
9 |
Correct |
4 ms |
19024 KB |
Output is correct |
10 |
Correct |
3 ms |
19024 KB |
Output is correct |
11 |
Correct |
3 ms |
19024 KB |
Output is correct |
12 |
Correct |
3 ms |
19024 KB |
Output is correct |
13 |
Correct |
4 ms |
19024 KB |
Output is correct |
14 |
Correct |
3 ms |
19264 KB |
Output is correct |
15 |
Correct |
4 ms |
19024 KB |
Output is correct |
16 |
Correct |
3 ms |
19024 KB |
Output is correct |
17 |
Correct |
3 ms |
19024 KB |
Output is correct |
18 |
Correct |
3 ms |
19196 KB |
Output is correct |
19 |
Correct |
3 ms |
19192 KB |
Output is correct |
20 |
Correct |
3 ms |
19096 KB |
Output is correct |
21 |
Correct |
4 ms |
19192 KB |
Output is correct |
22 |
Correct |
3 ms |
19092 KB |
Output is correct |
23 |
Correct |
3 ms |
19024 KB |
Output is correct |
24 |
Correct |
3 ms |
19024 KB |
Output is correct |
25 |
Correct |
3 ms |
19024 KB |
Output is correct |
26 |
Correct |
3 ms |
19024 KB |
Output is correct |
27 |
Correct |
3 ms |
19024 KB |
Output is correct |
28 |
Correct |
3 ms |
19024 KB |
Output is correct |
29 |
Correct |
3 ms |
19024 KB |
Output is correct |
30 |
Correct |
3 ms |
19024 KB |
Output is correct |
31 |
Correct |
3 ms |
19024 KB |
Output is correct |
32 |
Correct |
3 ms |
19024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
19024 KB |
Output is correct |
2 |
Correct |
4 ms |
19024 KB |
Output is correct |
3 |
Correct |
4 ms |
19088 KB |
Output is correct |
4 |
Correct |
4 ms |
19024 KB |
Output is correct |
5 |
Correct |
4 ms |
19024 KB |
Output is correct |
6 |
Correct |
5 ms |
19184 KB |
Output is correct |
7 |
Correct |
4 ms |
19024 KB |
Output is correct |
8 |
Correct |
4 ms |
19156 KB |
Output is correct |
9 |
Correct |
3 ms |
19092 KB |
Output is correct |
10 |
Correct |
3 ms |
19024 KB |
Output is correct |
11 |
Correct |
3 ms |
19024 KB |
Output is correct |
12 |
Correct |
3 ms |
19120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
18256 KB |
Output is correct |
2 |
Correct |
11 ms |
20096 KB |
Output is correct |
3 |
Correct |
16 ms |
18256 KB |
Output is correct |
4 |
Correct |
16 ms |
20304 KB |
Output is correct |
5 |
Correct |
10 ms |
20216 KB |
Output is correct |
6 |
Correct |
11 ms |
20216 KB |
Output is correct |
7 |
Correct |
12 ms |
20048 KB |
Output is correct |
8 |
Correct |
5 ms |
19024 KB |
Output is correct |
9 |
Correct |
4 ms |
19024 KB |
Output is correct |
10 |
Correct |
9 ms |
19792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
129 ms |
38152 KB |
Output is correct |
2 |
Correct |
127 ms |
36616 KB |
Output is correct |
3 |
Correct |
163 ms |
37948 KB |
Output is correct |
4 |
Correct |
192 ms |
36884 KB |
Output is correct |
5 |
Correct |
86 ms |
36616 KB |
Output is correct |
6 |
Correct |
72 ms |
33024 KB |
Output is correct |
7 |
Correct |
116 ms |
34116 KB |
Output is correct |
8 |
Correct |
17 ms |
24336 KB |
Output is correct |
9 |
Correct |
43 ms |
26960 KB |
Output is correct |
10 |
Correct |
81 ms |
35604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
497 ms |
72256 KB |
Output is correct |
2 |
Correct |
483 ms |
65864 KB |
Output is correct |
3 |
Correct |
700 ms |
72336 KB |
Output is correct |
4 |
Correct |
636 ms |
66248 KB |
Output is correct |
5 |
Correct |
394 ms |
67016 KB |
Output is correct |
6 |
Correct |
404 ms |
59336 KB |
Output is correct |
7 |
Correct |
383 ms |
57100 KB |
Output is correct |
8 |
Correct |
40 ms |
28360 KB |
Output is correct |
9 |
Correct |
46 ms |
30504 KB |
Output is correct |
10 |
Correct |
315 ms |
66112 KB |
Output is correct |
11 |
Correct |
421 ms |
72228 KB |
Output is correct |
12 |
Correct |
78 ms |
35880 KB |
Output is correct |