#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
#define ln '\n'
#define int long long
template <class _T>
bool chmin(_T &x, const _T &y){
bool flag = false;
if ( x > y ){
x = y; flag |= true;
}
return flag;
}
template <class _T>
bool chmax(_T &x, const _T &y){
bool flag = false;
if ( x < y ){
x = y; flag |= true;
}
return flag;
}
struct Hash{
const int Mod = 1e9 + 7, P = 29;
int n;
vector <int> p, pw;
Hash(string s) : n((int)s.size()), p(n + 1), pw(n + 1, 1) {
for ( int i = 0; i < n; i++ ){
pw[i + 1] = pw[i] * P % Mod;
p[i + 1] = (p[i] * P + (s[i] - 'a' + 1)) % Mod;
}
}
int get(int l, int r){
int v = p[r + 1] - (p[l] * pw[r - l + 1]) % Mod;
return v < 0 ? Mod + v : v;
}
};
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
string s; cin >> s;
int n = (int)s.size();
Hash u(s);
unordered_map <int,int> cnt[n + 1];
for ( int i = 0; i < n; i++ ){
int l = i, r = i;
while ( l >= 0 and r < n and s[l] == s[r] ){
cnt[r - l + 1][u.get(l, r)]++;
l--, r++;
}
l = i, r = i + 1;
while ( r < n and l >= 0 and s[l] == s[r] ){
cnt[r - l + 1][u.get(l, r)]++;
l--, r++;
}
}
int Mx = 0;
for ( int len = 1; len <= n; len++ ){
for ( auto [l, r]: cnt[len] ){
chmax(Mx, len * r);
}
}
cout << Mx;
cout << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
320 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
324 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
468 KB |
Output is correct |
2 |
Correct |
5 ms |
340 KB |
Output is correct |
3 |
Correct |
17 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
16 ms |
528 KB |
Output is correct |
6 |
Correct |
18 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
444 KB |
Output is correct |
8 |
Correct |
9 ms |
440 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
719 ms |
1828 KB |
Output is correct |
2 |
Correct |
410 ms |
1704 KB |
Output is correct |
3 |
Execution timed out |
1080 ms |
2420 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1072 ms |
9056 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1073 ms |
23424 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |