#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
bool chmin(int &x, int y){
bool flag = false;
if ( x > y ){
x = y; flag |= true;
}
return flag;
}
bool chmax(int &x, int 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();
map <int,int> mp;
Hash u(s);
for ( int i = 0; i < n; i++ ){
string c;
for ( int j = i; j < n; j++ ){
mp[u.get(i, j)]++;
}
}
int Mx = 0;
for ( int i = 0; i < n; i++ ){
chmax(Mx, mp[u.get(i, i)]);
for ( int j = i - 1; j >= 0; j-- ){
int l = j, r = (i - j) + i;
if ( r >= n or s[l] != s[r] ) break;
chmax(Mx, mp[u.get(l, r)] * (r - l + 1));
}
if ( i + 1 == n or s[i + 1] != s[i] ) continue;
chmax(Mx, mp[u.get(i, i+1)] * 2);
for ( int j = i - 1; j >= 0; j-- ){
int l = j, r = (i - j) + (i + 1);
if ( r >= n or s[j] != s[r] ) break;
chmax(Mx, mp[u.get(l, r)] * (r - l + 1));
}
}
cout << Mx;
cout << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 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 |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 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 |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
400 KB |
Output is correct |
29 |
Correct |
1 ms |
596 KB |
Output is correct |
30 |
Correct |
1 ms |
596 KB |
Output is correct |
31 |
Correct |
2 ms |
596 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
436 KB |
Output is correct |
2 |
Correct |
242 ms |
16904 KB |
Output is correct |
3 |
Correct |
36 ms |
328 KB |
Output is correct |
4 |
Correct |
322 ms |
28308 KB |
Output is correct |
5 |
Correct |
43 ms |
388 KB |
Output is correct |
6 |
Correct |
40 ms |
320 KB |
Output is correct |
7 |
Correct |
277 ms |
21440 KB |
Output is correct |
8 |
Correct |
36 ms |
340 KB |
Output is correct |
9 |
Correct |
379 ms |
29100 KB |
Output is correct |
10 |
Correct |
398 ms |
31496 KB |
Output is correct |
11 |
Correct |
410 ms |
31284 KB |
Output is correct |
12 |
Correct |
301 ms |
24208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1090 ms |
1620 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1073 ms |
14536 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1047 ms |
43072 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |