#include<iostream>
#include<map>
using namespace std;
typedef long long int lld;
#define MOD 1000000007
#define BASE 257
lld hash2[1000000];
lld hash3[1000000];
lld pow[1000000];
int n;
bool palindrome(int a, int b){
lld A=hash3[b+1]-hash3[a];
A*=pow[n-1-a];
lld B=hash2[a]-hash2[b+1];
B*=pow[b];
A%=MOD;
B%=MOD;
if(B<0)B+=MOD;
if(A<0)A+=MOD;
//cout<<a<<" "<<b<<" "<<A<<" "<<B<<endl;
if(A%MOD==B%MOD)return true;
return false;
}
lld val(int a, int b){
lld A=hash3[b+1]-hash3[a];
A*=pow[n-1-a];
A%=MOD;
if(A<0)A+=MOD;
return A;
}
int main(){
string s;
cin>>s;
n=s.size();
hash3[0]=0;
lld v=1;
for(int i=1;i<=n;i++){
hash3[i]=(s.at(i-1))*v+hash3[i-1];
hash3[i]%=MOD;
pow[i-1]=v;
v*=BASE;
v%=MOD;
}
hash2[n]=0;
v=1;
for(int i=n-1;i>-1;i--){
hash2[i]=(s.at(i))*v+hash2[i+1];
hash2[i]%=MOD;
v*=BASE;
v%=MOD;
}
//cout<<hash2[0]<<" "<<hash[n]<<endl;
lld ans=0;
for(lld len=1;len<=n;len++){
map<lld,int> m;
//cout<<hash[i]<<" "<<hash2[i]<<endl;
for(int i=0;i+len-1<n;i++){
if(palindrome(i,i+len-1)){
lld H=val(i,i+len-1);
map<lld,int>::iterator it=m.find(H);
if(it==m.end()){
m[H]=1;
ans=max(ans,len);
//cout<<len<<endl;
}else{
it->second++;
ans=max(ans,it->second*len);
//cout<<it->second*len<<endl;
}
}
}
//cout<<(hash[i]+hash2[i])%MOD<<endl;
}cout<<ans<<endl;
//cout<<palindrome(0,2)<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
3 ms |
524 KB |
Output is correct |
4 |
Correct |
3 ms |
572 KB |
Output is correct |
5 |
Correct |
2 ms |
688 KB |
Output is correct |
6 |
Correct |
3 ms |
688 KB |
Output is correct |
7 |
Correct |
2 ms |
692 KB |
Output is correct |
8 |
Correct |
2 ms |
696 KB |
Output is correct |
9 |
Correct |
2 ms |
704 KB |
Output is correct |
10 |
Correct |
2 ms |
748 KB |
Output is correct |
11 |
Correct |
3 ms |
760 KB |
Output is correct |
12 |
Correct |
3 ms |
760 KB |
Output is correct |
13 |
Correct |
2 ms |
764 KB |
Output is correct |
14 |
Correct |
2 ms |
768 KB |
Output is correct |
15 |
Correct |
2 ms |
772 KB |
Output is correct |
16 |
Correct |
2 ms |
776 KB |
Output is correct |
17 |
Correct |
3 ms |
800 KB |
Output is correct |
18 |
Correct |
3 ms |
804 KB |
Output is correct |
19 |
Correct |
2 ms |
808 KB |
Output is correct |
20 |
Correct |
2 ms |
808 KB |
Output is correct |
21 |
Correct |
3 ms |
808 KB |
Output is correct |
22 |
Correct |
2 ms |
820 KB |
Output is correct |
23 |
Correct |
3 ms |
824 KB |
Output is correct |
24 |
Correct |
3 ms |
828 KB |
Output is correct |
25 |
Correct |
3 ms |
832 KB |
Output is correct |
26 |
Correct |
3 ms |
836 KB |
Output is correct |
27 |
Correct |
3 ms |
840 KB |
Output is correct |
28 |
Correct |
2 ms |
844 KB |
Output is correct |
29 |
Correct |
4 ms |
848 KB |
Output is correct |
30 |
Correct |
2 ms |
852 KB |
Output is correct |
31 |
Correct |
2 ms |
852 KB |
Output is correct |
32 |
Correct |
2 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
864 KB |
Output is correct |
2 |
Correct |
11 ms |
864 KB |
Output is correct |
3 |
Correct |
17 ms |
872 KB |
Output is correct |
4 |
Correct |
9 ms |
872 KB |
Output is correct |
5 |
Correct |
11 ms |
880 KB |
Output is correct |
6 |
Correct |
12 ms |
1012 KB |
Output is correct |
7 |
Correct |
7 ms |
1012 KB |
Output is correct |
8 |
Correct |
12 ms |
1012 KB |
Output is correct |
9 |
Correct |
7 ms |
1012 KB |
Output is correct |
10 |
Correct |
8 ms |
1012 KB |
Output is correct |
11 |
Correct |
11 ms |
1012 KB |
Output is correct |
12 |
Correct |
10 ms |
1012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
706 ms |
1192 KB |
Output is correct |
2 |
Correct |
568 ms |
1216 KB |
Output is correct |
3 |
Correct |
844 ms |
1336 KB |
Output is correct |
4 |
Correct |
755 ms |
1336 KB |
Output is correct |
5 |
Correct |
481 ms |
1336 KB |
Output is correct |
6 |
Correct |
489 ms |
1336 KB |
Output is correct |
7 |
Correct |
526 ms |
1336 KB |
Output is correct |
8 |
Correct |
482 ms |
1408 KB |
Output is correct |
9 |
Incorrect |
488 ms |
1436 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1087 ms |
3648 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1069 ms |
8896 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |