| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 474027 | jangwonyoung | 회문 (APIO14_palindrome) | C++14 | 210 ms | 98904 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const int N=3e5+5;
int n;
string s;
int f[226];
int sz=1;
const int ts=6e5+5;
int ch[ts][26];
int fa[ts],len[ts];
int mp[ts];
int king[N];
vector<int>adj[ts];
int rsz[ts];
int fi[ts],pl[ts];
void dfs(int id){
for(auto c:adj[id]){
dfs(c);
rsz[id]+=rsz[c];
}
}
void dfs2(int id){
for(auto c:adj[id]){
dfs2(c);
if(fi[c]!=0){
int i=fi[c];
int cl=len[id];
int x=id;
if(i+cl-1>=mp[x]){
if(mp[x]-i+1>len[fa[x]]){
pl[x]=mp[x]-i+1;
}
}
fi[id]=max(fi[id],fi[c]);
}
}
}
int main(){
ios::sync_with_stdio(false);
for(int i='a'; i<='z' ;i++) f[i]=i-'a';
cin >> s;n=s.size();s='?'+s;
int x=1;
for(int i=1; i<=n ;i++){
char c=s[i];
int y=++sz;len[y]=i;
while(x && !ch[x][f[c]]){
ch[x][f[c]]=y;
x=fa[x];
}
if(!x){
fa[y]=1;
}
else if(len[x]+1==len[ch[x][f[c]]]){
fa[y]=ch[x][f[c]];
}
else{
int w=ch[x][f[c]];
int z=++sz;len[z]=len[x]+1;
for(int j=0; j<26 ;j++) ch[z][j]=ch[w][j];
fa[z]=fa[w];fa[w]=z;
while(ch[x][f[c]]==w){
ch[x][f[c]]=z;
x=fa[x];
}
fa[y]=z;
}
king[i]=x=y;
}
for(int i=2; i<=ts ;i++){
adj[fa[i]].push_back(i);
}
for(int i=n; i>=1 ;i--){
int x=king[i];
while(!mp[x]){
mp[x]=i;x=fa[x];
}
rsz[king[i]]++;
}
dfs(1);
x=1;
int cl=0;
for(int i=n; i>=1 ;i--){
char c=s[i];
while(ch[x][f[c]]==0){
x=fa[x];
cl=len[x];
}
x=ch[x][f[c]];
cl++;
if(fi[x]==0) fi[x]=i;
if(i+cl-1>=mp[x]){
if(mp[x]-i+1>len[fa[x]]){
pl[x]=mp[x]-i+1;
}
}
}
dfs2(1);
ll ans=0;
for(int i=1; i<=sz ;i++){
//cout << pl[i] << '\n';
if(pl[i]!=0) ans=max(ans,1LL*pl[i]*rsz[i]);
}
cout << ans << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
| # | 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... | ||||
