QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#743974 | #801. 回文自动机 | HJR | 0 | 2ms | 11900kb | C++17 | 1.8kb | 2024-11-13 20:29:06 | 2024-11-13 20:29:07 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define debug(x) cout<<#x<<": "<<x<<endl
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll=long long;
using ull=unsigned long long;
const int N=1e6+10;
struct PAM {
char s[N];
int cnt[N],len[N],fail[N],next[N][26];
int tot,last;
void init() {
while(tot>=0){
cnt[tot]=len[tot]=fail[tot]=0;
memset(next[tot],0,sizeof next[tot]);
tot--;
}
last=1;
newnode(0);
newnode(-1);
s[0]=s[1] = '$';
fail[0] = 1;
}
int newnode(int l) { // 建立一个新节点,长度为 l
tot++;
len[tot] = l;
fail[tot] = cnt[tot] = 0;
return tot;
}
int getfail(int x) { // 找后缀回文
while (s[tot - len[x] - 1] != s[tot]) x = fail[x];
return x;
}
void insert(int c) { // 建树
s[++tot] = c;
int now = getfail(last);
if (!next[now][c]) {
int x = newnode(len[now] + 2);
fail[x] = next[getfail(fail[now])][c];
next[now][c] = x;
}
last = next[now][c];
cnt[last]++;
}
ll work(){
for(int i=tot;i>=2;i--){
cnt[fail[i]]+=cnt[i];
}
ll ans=0;
for(int i=2;i<=tot;i++){
ans=max(ans,1ll*cnt[i]*len[i]*len[i]);
}
return ans;
}
}pam;
void solve(){
pam.init();
string s;
cin>>s;
for(auto x:s){
pam.insert(x-'a');
}
cout<<pam.work();
}
signed main(){
ios::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
int t=1;
while(t--){
solve();
}
}
/*
贡献法
正难则反
数小状压
关系连边
拆位
广义单调性
最长转最短
*/
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 11900kb
input:
bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...
output:
22356
result:
wrong answer expected '5594', found '22356'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%