#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define X first
#define Y second
#define SZ(x) (int)(x).size()
const int mod=1e9+9;
int qpow(int x,int t){
if(t==0){return 1;}
if(t%2==1){return qpow(x,t-1)*x%mod;}
int xx=qpow(x,t/2);
return xx*xx%mod;
}
int tme[500005];
struct rlhsh{
vector<int>hsh;
int n;
void init(string s){
n=s.size();
hsh.resize(s.size()+10,0);
for(int i=1;i<=n;i++){
hsh[i]=(hsh[i-1]+(s[i-1]-'a'+1)*tme[i])%mod;
}
}
int gthsh(int l,int r){
int ret=(hsh[r]-hsh[l-1]+mod)*qpow(tme[l-1],mod-2)%mod;
return ret;
}
};
int n;
pair<int,int>rev(int l,int r){
l=n-l+1;r=n-r+1;
swap(l,r);
return {l,r};
}
string s;
signed main(){
tme[0]=1;
for(int i=1;i<=500000;i++){
tme[i]=tme[i-1]*37%mod;
}
cin>>s;
n=s.size();
rlhsh sh;
sh.init(s);
reverse(s.begin(),s.end());
rlhsh rsh;
rsh.init(s);
int ans=1;
map<int,int>mp;
for(int i=1;i<=n;i++){
for(int j=i;j<=n;j++){
int v=sh.gthsh(i,j);
if(v==rsh.gthsh(n-j+1,n-i+1)){
mp[v]++;
ans=max(ans,mp[v]*(j-i+1));
}
}
}
cout<<ans<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4188 KB |
Output is correct |
2 |
Correct |
3 ms |
4352 KB |
Output is correct |
3 |
Correct |
3 ms |
4184 KB |
Output is correct |
4 |
Correct |
4 ms |
4188 KB |
Output is correct |
5 |
Correct |
4 ms |
4188 KB |
Output is correct |
6 |
Correct |
3 ms |
4188 KB |
Output is correct |
7 |
Correct |
4 ms |
4188 KB |
Output is correct |
8 |
Correct |
4 ms |
4188 KB |
Output is correct |
9 |
Correct |
4 ms |
4188 KB |
Output is correct |
10 |
Correct |
4 ms |
4184 KB |
Output is correct |
11 |
Correct |
4 ms |
4188 KB |
Output is correct |
12 |
Correct |
4 ms |
4188 KB |
Output is correct |
13 |
Correct |
4 ms |
4184 KB |
Output is correct |
14 |
Correct |
4 ms |
4188 KB |
Output is correct |
15 |
Correct |
4 ms |
4348 KB |
Output is correct |
16 |
Correct |
4 ms |
4188 KB |
Output is correct |
17 |
Correct |
4 ms |
4184 KB |
Output is correct |
18 |
Correct |
4 ms |
4188 KB |
Output is correct |
19 |
Correct |
6 ms |
4352 KB |
Output is correct |
20 |
Correct |
6 ms |
4440 KB |
Output is correct |
21 |
Correct |
5 ms |
4188 KB |
Output is correct |
22 |
Correct |
5 ms |
4188 KB |
Output is correct |
23 |
Correct |
6 ms |
4280 KB |
Output is correct |
24 |
Correct |
5 ms |
4188 KB |
Output is correct |
25 |
Correct |
6 ms |
4244 KB |
Output is correct |
26 |
Correct |
6 ms |
4188 KB |
Output is correct |
27 |
Correct |
6 ms |
4192 KB |
Output is correct |
28 |
Correct |
6 ms |
4188 KB |
Output is correct |
29 |
Correct |
6 ms |
4188 KB |
Output is correct |
30 |
Correct |
6 ms |
4188 KB |
Output is correct |
31 |
Correct |
5 ms |
4188 KB |
Output is correct |
32 |
Correct |
6 ms |
4188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
240 ms |
4188 KB |
Output is correct |
2 |
Correct |
226 ms |
4412 KB |
Output is correct |
3 |
Correct |
248 ms |
4408 KB |
Output is correct |
4 |
Correct |
222 ms |
4692 KB |
Output is correct |
5 |
Correct |
247 ms |
4184 KB |
Output is correct |
6 |
Correct |
247 ms |
4408 KB |
Output is correct |
7 |
Correct |
219 ms |
4364 KB |
Output is correct |
8 |
Correct |
252 ms |
4188 KB |
Output is correct |
9 |
Correct |
222 ms |
4884 KB |
Output is correct |
10 |
Correct |
219 ms |
4188 KB |
Output is correct |
11 |
Correct |
217 ms |
4188 KB |
Output is correct |
12 |
Correct |
221 ms |
4876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1063 ms |
4956 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1022 ms |
12368 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1054 ms |
28792 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |