This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#define PRINT(x) cerr<<#x<<'='<<x<<endl;
using namespace std;
const int P_SIGMA = 26;
const int MINUS_NODE = 1;
const int ZERO_NODE = 2;
struct Node {
int len, slink, cnt, dub;
int to[P_SIGMA];
Node(int _len = 0, int _slink = 0, int _cnt = 0, int _depth = 0) {
len = _len; slink = _slink; cnt = _cnt; dub = _depth;
for(int i = 0; i < P_SIGMA; i++) to[i] = 0;
}
};
string s;
vector<Node> pt;
int suff;
void init() {
suff = 2;
s = "";
pt.push_back(Node(0));
pt.push_back(Node(-1, MINUS_NODE));
pt.push_back(Node(0, MINUS_NODE));
}
int addLetter(char c) {
s += c;
int cidx = c-'a';
int len = s.size();
while(c != s[len-2-pt[suff].len]) {
suff = pt[suff].slink;
}
int nd = pt[suff].to[cidx];
if(nd == 0) {
nd = pt.size();
pt[suff].to[cidx] = nd;
pt.push_back(Node(pt[suff].len+2));
if(suff == MINUS_NODE) {
pt[nd].slink = ZERO_NODE;
} else {
int u = pt[suff].slink;
while(c != s[len-2-pt[u].len]) {
u = pt[u].slink;
}
pt[nd].slink = pt[u].to[cidx];
}
pt[nd].dub = pt[pt[nd].slink].dub+1;
}
pt[nd].cnt++;
suff = nd;
return pt[nd].dub;
}
void calcCnt() {
for(int i = pt.size()-1; i > 2; i--) {
pt[pt[i].slink].cnt += pt[i].cnt;
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
string s; cin >> s;
init();
for(auto x : s) {
addLetter(x);
}
calcCnt();
long long rez = 0;
for(int i = pt.size()-1; i > 2; i--) {
rez = max(rez, (long long) pt[i].len*pt[i].cnt);
}
cout << rez << endl;
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... |