# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
493464 | MasterTaster | 회문 (APIO14_palindrome) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define xx first
#define yy second
#define MAXN 600010
using namespace std;
struct PalTree{
struct Node{
int len, cnt, to[26], dub, slink;
Node() { len=0; cnt=0; dub=0; slink=0; for (int i=0; i<26; i++) to[i]=-1; }
Node(int a, int b, int c, int d)
{
len=a; cnt=b; dub=c; slink=d;
for (int i=0; i<26; i++) to[i]=-1;
}
};
vector<Node> pt;
int suff;
int s[MAXN];
int gde=0;
void addLetter(int c)
{
cout<<gde<<" "<<suff<<endl;
s[gde]=c;
while (c!=s[gde-1-pt[suff].len])
suff=pt[suff].slink;
cout<<suff<<endl;
int slnd=pt[suff].to[c];
if (slnd==-1)
{
slnd=pt.size();
pt[suff].to[c]=slnd;
pt.pb(Node(pt[suff].len+2, 0, 0, 0));
if (suff==1)
pt[slnd].slink=2;
else
{
int pom=pt[suff].slink;
while(c!=s[gde-1-pt[pom].len])
pom=pt[pom].slink;
pt[slnd].slink=pt[pom].to[c];
assert(pt[i].slink<pt.size());
}
pt[slnd].dub=pt[pt[slnd].slink].dub+1;
}
pt[slnd].cnt++;
suff=slnd;
gde++;
cout<<slnd<<" "<<pt[slnd].slink<<endl;
}
void calc()
{
for (int i=pt.size()-1; i>2; i--){ pt[pt[i].slink].cnt+=pt[i].cnt; }
}
void init()
{
pt.clear();
pt.pb(Node(-1, -1, -1, -1));
pt.pb(Node(-1, 0, 0, 1));
pt.pb(Node(0, 0, 0, 1));
suff=2;
}
Node &operator[](int idx) {
return pt[idx];
}
};
PalTree pt;
ll ress=-1;
string st;
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>st;
pt.init();
for (int i=0; i<st.size(); i++) pt.addLetter((int)(st[i]-'a'));
pt.calc();
for (int i=3; i<pt.pt.size(); i++)
{
ress=max(ress, ((ll)pt[i].cnt*pt[i].len));
}
cout<<ress;
}