#include <bits/stdc++.h>
#define N 300005
#define K 30
using namespace std;
const int base = 31;
const int mod = 1e9 + 7;
const int base2 = 37;
const int mod2 = 1e9 + 9;
int cnt[N][K];
int val[N];
long long pre[N];
long long pw[N];
long long pre2[N];
long long pw2[N];
vector<int> palindromes[N];
void solve(){
string s;
cin >> s;
int n = s.size();
s = "." + s;
for(int i=1;i<=n;i++){
pre[i] = (pre[i-1] * base + (s[i] - 'a'))%mod;
pre2[i] = (pre2[i-1] * base2 + (s[i] - 'a'))%mod2;
}
long long ans = 0;
map<string,int> mp;
for(int i = n;i>=1;i--){
if(i == n || s[i+1] != s[i]){
val[i] = 1;
}
else val[i] = val[i+1] + 1;
palindromes[i].push_back(i + val[i] - 1);
cnt[val[i]][s[i] - 'a']++;
for(auto u:palindromes[i+1]){
if(u + 1 <= n && s[u+1] == s[i] && u + 1 > i + val[i] - 1){
palindromes[i].push_back(u+1);
}
}
for(auto u:palindromes[i]){
//cout << u << " " << s.substr(i,u - i + 1) << " ";
ans = max(ans,1ll*(u-i + 1) * (++mp[s.substr(i,u - i + 1)]));
}
//cout << endl;
}
for(int i=n;i>=1;i--){
for(int c = 0;c<K;c++){
cnt[i][c] += cnt[i+1][c];
ans = max(ans,1ll*i*cnt[i][c]);
}
}
cout << ans;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
pw[0] = 1;
pw2[0] = 1;
for(int i = 1;i<N;i++){
pw[i] = pw[i-1] * base % mod;
pw2[i] = pw2[i-1] * base2 % mod2;
}
int t=1;
//cin>>t;
while(t--){
solve();
}
#ifdef Local
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
#endif
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
12120 KB |
Output is correct |
2 |
Correct |
8 ms |
11988 KB |
Output is correct |
3 |
Correct |
8 ms |
11988 KB |
Output is correct |
4 |
Correct |
8 ms |
11968 KB |
Output is correct |
5 |
Correct |
7 ms |
12068 KB |
Output is correct |
6 |
Correct |
7 ms |
11988 KB |
Output is correct |
7 |
Correct |
8 ms |
12092 KB |
Output is correct |
8 |
Correct |
7 ms |
11988 KB |
Output is correct |
9 |
Correct |
7 ms |
12036 KB |
Output is correct |
10 |
Correct |
9 ms |
11988 KB |
Output is correct |
11 |
Correct |
8 ms |
11988 KB |
Output is correct |
12 |
Correct |
8 ms |
11988 KB |
Output is correct |
13 |
Correct |
8 ms |
11988 KB |
Output is correct |
14 |
Correct |
8 ms |
11988 KB |
Output is correct |
15 |
Correct |
7 ms |
11988 KB |
Output is correct |
16 |
Correct |
11 ms |
12076 KB |
Output is correct |
17 |
Correct |
8 ms |
11996 KB |
Output is correct |
18 |
Correct |
8 ms |
11972 KB |
Output is correct |
19 |
Correct |
7 ms |
12068 KB |
Output is correct |
20 |
Correct |
7 ms |
12116 KB |
Output is correct |
21 |
Correct |
8 ms |
12116 KB |
Output is correct |
22 |
Correct |
7 ms |
11988 KB |
Output is correct |
23 |
Correct |
8 ms |
12116 KB |
Output is correct |
24 |
Correct |
8 ms |
12000 KB |
Output is correct |
25 |
Correct |
9 ms |
11988 KB |
Output is correct |
26 |
Correct |
8 ms |
12116 KB |
Output is correct |
27 |
Correct |
9 ms |
11988 KB |
Output is correct |
28 |
Correct |
8 ms |
12116 KB |
Output is correct |
29 |
Correct |
9 ms |
12104 KB |
Output is correct |
30 |
Correct |
8 ms |
12064 KB |
Output is correct |
31 |
Correct |
8 ms |
11988 KB |
Output is correct |
32 |
Correct |
8 ms |
12104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
62 ms |
14056 KB |
Output is correct |
2 |
Correct |
27 ms |
13176 KB |
Output is correct |
3 |
Correct |
10 ms |
12756 KB |
Output is correct |
4 |
Correct |
12 ms |
12500 KB |
Output is correct |
5 |
Correct |
8 ms |
12756 KB |
Output is correct |
6 |
Correct |
9 ms |
12756 KB |
Output is correct |
7 |
Correct |
9 ms |
12628 KB |
Output is correct |
8 |
Correct |
62 ms |
14160 KB |
Output is correct |
9 |
Correct |
9 ms |
12384 KB |
Output is correct |
10 |
Correct |
8 ms |
12204 KB |
Output is correct |
11 |
Correct |
8 ms |
12244 KB |
Output is correct |
12 |
Correct |
9 ms |
12500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1077 ms |
30716 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1057 ms |
32056 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1054 ms |
34752 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |