이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#define int long long
using namespace std;
const int MAX_N = 3 * 1e5;
const int SIGMA = 26;
string s;
struct Node {
int next[SIGMA];
int sufflink;
int len;
int num;
int occ = 0;
};
Node tree[MAX_N + 3];
int cnt = 2, suffix = 2;
void addletter(int pos) {
int let = s[pos] - 'a';
int cur = suffix, curlen = 0;
while (true) {
curlen = tree[cur].len;
if (pos - curlen - 1 >= 0 && s[pos - curlen - 1] == s[pos]) {
break;
}
cur = tree[cur].sufflink;
}
if (tree[cur].next[let]) {
suffix = tree[cur].next[let];
return;
}
cnt++;
suffix = cnt;
tree[cnt].len = tree[cur].len + 2;
tree[cur].next[let] = cnt;
if (tree[cnt].len == 1) {
tree[cnt].sufflink = 2;
tree[cnt].num = 1;
return;
}
while (true) {
cur = tree[cur].sufflink;
curlen = tree[cur].len;
if (pos - curlen - 1 >= 0 && s[pos - curlen - 1] == s[pos]) {
tree[cnt].sufflink = tree[cur].next[let];
break;
}
}
tree[cnt].num = tree[tree[cnt].sufflink].num + 1;
}
void init() {
tree[1].len = -1;
tree[1].sufflink = 1;
tree[2].len = 0;
tree[2].sufflink = 1;
}
signed main() {
cin >> s;
int n = s.size();
init();
for (int i = 0; i < n; i++) {
addletter(i);
}
int answer = 0;
for (int i = cnt; i >= 1; i--) {
tree[i].occ++;
answer = max(answer, tree[i].occ * tree[i].len);
tree[tree[i].sufflink].occ += tree[i].occ;
}
cout << answer;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |