#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define X first
#define Y second
#define sep ' '
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl;
const ll MAXN = 1e6 + 10;
const ll SIG = 26;
int nxt[MAXN][SIG], F[MAXN], len[MAXN], sz, v, cnt[MAXN];
string s;
inline void add(int pos) {
while (pos - 1 - len[v] < 0 || s[pos] != s[pos - 1 - len[v]])
v = F[v];
int c = s[pos] - 'a';
if (!nxt[v][c]) {
nxt[v][c] = ++sz;
len[sz] = len[v] + 2;
v = F[v];
while (s[pos] != s[pos - 1 - len[v]]) v = F[v];
if (len[sz] > 1) F[sz] = nxt[v][c];
else F[sz] = 1;
v = sz;
cnt[sz]++;
} else {
v = nxt[v][c];
cnt[v]++;
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
sz = v = 1;
len[0] = -1;
len[1] = F[1] = 0;
cin >> s;
for (int i = 0; i < int(s.size()); i++)
add(i);
ll ans = 0;
for (int i = sz; i > 0; i--) {
ans = max(ans, 1ll * cnt[i] * len[i]);
cnt[F[i]] += cnt[i];
}
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
352 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
352 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
1 ms |
1492 KB |
Output is correct |
3 |
Correct |
1 ms |
1492 KB |
Output is correct |
4 |
Correct |
1 ms |
1492 KB |
Output is correct |
5 |
Correct |
1 ms |
1492 KB |
Output is correct |
6 |
Correct |
1 ms |
1492 KB |
Output is correct |
7 |
Correct |
1 ms |
1492 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
11988 KB |
Output is correct |
2 |
Correct |
8 ms |
11928 KB |
Output is correct |
3 |
Correct |
8 ms |
12004 KB |
Output is correct |
4 |
Correct |
10 ms |
12008 KB |
Output is correct |
5 |
Correct |
11 ms |
11988 KB |
Output is correct |
6 |
Correct |
8 ms |
8936 KB |
Output is correct |
7 |
Correct |
8 ms |
10272 KB |
Output is correct |
8 |
Correct |
2 ms |
708 KB |
Output is correct |
9 |
Correct |
3 ms |
3284 KB |
Output is correct |
10 |
Correct |
7 ms |
10196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
35056 KB |
Output is correct |
2 |
Correct |
23 ms |
35060 KB |
Output is correct |
3 |
Correct |
22 ms |
35032 KB |
Output is correct |
4 |
Correct |
24 ms |
35056 KB |
Output is correct |
5 |
Correct |
31 ms |
35088 KB |
Output is correct |
6 |
Correct |
24 ms |
31200 KB |
Output is correct |
7 |
Correct |
22 ms |
29356 KB |
Output is correct |
8 |
Correct |
5 ms |
1264 KB |
Output is correct |
9 |
Correct |
7 ms |
1244 KB |
Output is correct |
10 |
Correct |
20 ms |
28884 KB |
Output is correct |
11 |
Correct |
23 ms |
35056 KB |
Output is correct |
12 |
Correct |
7 ms |
4316 KB |
Output is correct |