#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 7;
struct node{
int len, cnt;
node *nxt[26], *suf;
node(int _len = 0){
len = _len;
cnt = 0;
for(int i = 0; i < 26; i++)
nxt[i] = nullptr;
suf = nullptr;
}
};
string s;
node *root1, *root2, *cur;
vector <node*> a[N];
void insert(int pos){
int id = s[pos] - 'a';
if (pos - cur->len - 1 < 0)
cur = cur->suf;
while(s[pos] != s[pos - cur->len - 1])
cur = cur->suf;
if (cur->nxt[id] != nullptr){
cur = cur->nxt[id];
return;
}
cur->nxt[id] = new node(cur->len + 2);
if (cur == root1){
cur->nxt[id]->suf = root2;
} else {
node *tmp = cur->suf;
while(s[pos] != s[pos - tmp->len - 1])
tmp = tmp->suf;
cur->nxt[id]->suf = tmp->nxt[id];
}
cur = cur->nxt[id];
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> s;
root1 = new node(-1);
root2 = new node(0);
root2->suf = root1;
cur = root2;
for(int i = 0; i < (int) s.size(); i++){
insert(i);
a[cur->len].push_back(cur);
cur->cnt++;
}
ll res = 0;
for(int i = s.size(); i >= 1; i--)
for(node *cur : a[i]){
res = max(res, (ll) cur->len * cur->cnt);
cur->suf->cnt += cur->cnt;
cur->cnt = 0;
}
cout << res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7244 KB |
Output is correct |
2 |
Correct |
5 ms |
7244 KB |
Output is correct |
3 |
Correct |
5 ms |
7368 KB |
Output is correct |
4 |
Correct |
5 ms |
7244 KB |
Output is correct |
5 |
Correct |
5 ms |
7368 KB |
Output is correct |
6 |
Correct |
5 ms |
7244 KB |
Output is correct |
7 |
Correct |
5 ms |
7244 KB |
Output is correct |
8 |
Correct |
4 ms |
7244 KB |
Output is correct |
9 |
Correct |
4 ms |
7372 KB |
Output is correct |
10 |
Correct |
4 ms |
7244 KB |
Output is correct |
11 |
Correct |
4 ms |
7364 KB |
Output is correct |
12 |
Correct |
4 ms |
7372 KB |
Output is correct |
13 |
Correct |
4 ms |
7360 KB |
Output is correct |
14 |
Correct |
4 ms |
7372 KB |
Output is correct |
15 |
Correct |
4 ms |
7312 KB |
Output is correct |
16 |
Correct |
4 ms |
7264 KB |
Output is correct |
17 |
Correct |
4 ms |
7328 KB |
Output is correct |
18 |
Correct |
4 ms |
7244 KB |
Output is correct |
19 |
Correct |
4 ms |
7372 KB |
Output is correct |
20 |
Correct |
6 ms |
7368 KB |
Output is correct |
21 |
Correct |
5 ms |
7372 KB |
Output is correct |
22 |
Correct |
4 ms |
7364 KB |
Output is correct |
23 |
Correct |
4 ms |
7372 KB |
Output is correct |
24 |
Correct |
5 ms |
7372 KB |
Output is correct |
25 |
Correct |
5 ms |
7364 KB |
Output is correct |
26 |
Correct |
5 ms |
7276 KB |
Output is correct |
27 |
Correct |
5 ms |
7372 KB |
Output is correct |
28 |
Correct |
4 ms |
7372 KB |
Output is correct |
29 |
Correct |
4 ms |
7372 KB |
Output is correct |
30 |
Correct |
6 ms |
7372 KB |
Output is correct |
31 |
Correct |
5 ms |
7376 KB |
Output is correct |
32 |
Correct |
5 ms |
7372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7500 KB |
Output is correct |
2 |
Correct |
5 ms |
7500 KB |
Output is correct |
3 |
Correct |
4 ms |
7628 KB |
Output is correct |
4 |
Correct |
5 ms |
7576 KB |
Output is correct |
5 |
Correct |
6 ms |
7616 KB |
Output is correct |
6 |
Correct |
5 ms |
7616 KB |
Output is correct |
7 |
Correct |
6 ms |
7556 KB |
Output is correct |
8 |
Correct |
5 ms |
7500 KB |
Output is correct |
9 |
Correct |
5 ms |
7500 KB |
Output is correct |
10 |
Correct |
5 ms |
7372 KB |
Output is correct |
11 |
Correct |
5 ms |
7360 KB |
Output is correct |
12 |
Correct |
5 ms |
7576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9804 KB |
Output is correct |
2 |
Correct |
7 ms |
9804 KB |
Output is correct |
3 |
Correct |
7 ms |
9932 KB |
Output is correct |
4 |
Correct |
7 ms |
9992 KB |
Output is correct |
5 |
Correct |
7 ms |
9928 KB |
Output is correct |
6 |
Correct |
7 ms |
9804 KB |
Output is correct |
7 |
Correct |
7 ms |
9860 KB |
Output is correct |
8 |
Correct |
6 ms |
7628 KB |
Output is correct |
9 |
Correct |
7 ms |
7628 KB |
Output is correct |
10 |
Correct |
6 ms |
9164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
32588 KB |
Output is correct |
2 |
Correct |
34 ms |
32856 KB |
Output is correct |
3 |
Correct |
31 ms |
34124 KB |
Output is correct |
4 |
Correct |
30 ms |
33044 KB |
Output is correct |
5 |
Correct |
32 ms |
32776 KB |
Output is correct |
6 |
Correct |
27 ms |
26312 KB |
Output is correct |
7 |
Correct |
35 ms |
29124 KB |
Output is correct |
8 |
Correct |
10 ms |
8860 KB |
Output is correct |
9 |
Correct |
14 ms |
14372 KB |
Output is correct |
10 |
Correct |
28 ms |
29456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
82980 KB |
Output is correct |
2 |
Correct |
92 ms |
83556 KB |
Output is correct |
3 |
Correct |
93 ms |
87728 KB |
Output is correct |
4 |
Correct |
76 ms |
85000 KB |
Output is correct |
5 |
Correct |
87 ms |
83904 KB |
Output is correct |
6 |
Correct |
83 ms |
75040 KB |
Output is correct |
7 |
Correct |
91 ms |
70984 KB |
Output is correct |
8 |
Correct |
16 ms |
12616 KB |
Output is correct |
9 |
Correct |
16 ms |
12616 KB |
Output is correct |
10 |
Correct |
95 ms |
71176 KB |
Output is correct |
11 |
Correct |
95 ms |
83020 KB |
Output is correct |
12 |
Correct |
22 ms |
17692 KB |
Output is correct |