QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#481175 | #801. 回文自动机 | wdnmdwrnmmp# | 0 | 4ms | 29864kb | C++14 | 1.2kb | 2024-07-16 21:07:55 | 2024-07-16 21:07:56 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
// #define int long long
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
typedef vector<int> vi;
typedef pair<int,int> pi;
namespace pam{
const int N=1e6+5;
string str;
int s[N][26], fa[N], len[N], cnt[N], tot=1;
vi G[N];
int getfa(int u,int pos){
while(str[pos-len[u]-1]!=str[pos]){
u=fa[u];
}
return u;
}
int ins(int u,int pos){
int c=str[pos]-'a';
u=getfa(u, pos);
if(!s[u][c]){
s[u][c]=++tot;
len[s[u][c]]=len[u]+2;
fa[s[u][c]]=getfa(fa[u], pos);
if(fa[s[u][c]]==0){
fa[s[u][c]]=1;
}
}
return s[u][c];
}
void dfs(int u){
for(int v:G[u]){
dfs(v);
cnt[u]+= cnt[v];
}
}
void solve(string _str){
str=_str;
len[0]=-1;
int cur=0;
rep(i,0,(int)str.size()-1){
cur=ins(cur, i);
cnt[cur]++;
}
rep(i,1,tot){
G[fa[i]].pb(i);
}
dfs(0);
long long ans=0;
rep(i,1,tot){
ans=max(ans, (long long)len[i]*len[i]*cnt[i]);
}
cout<< ans <<'\n';
}
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
string s; cin>>s;
pam::solve(s);
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 29864kb
input:
bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...
output:
3978
result:
wrong answer expected '5594', found '3978'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%