QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#743916#801. 回文自动机HJR0 2ms12096kbC++171.8kb2024-11-13 20:18:172024-11-13 20:18:17

Judging History

你现在查看的是最新测评结果

  • [2024-11-13 20:18:17]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:12096kb
  • [2024-11-13 20:18:17]
  • 提交

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 sz,tot,last;
    void init() {
        while(sz>=0){
            cnt[sz]=len[sz]=fail[sz]=0;
            memset(next[sz],0,sizeof next[sz]);
            sz--;
        }
        sz=-1;
        tot=last=1;
        newnode(0);
        newnode(-1);
        s[0] = '$';
        fail[0] = 1;
    }
    int newnode(int l) {  // 建立一个新节点,长度为 l
        sz++;
        len[sz] = l;
        fail[sz] = cnt[sz] = 0;
        return sz;
    }
    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=sz;i>=2;i--){
            cnt[fail[i]]+=cnt[i];
        }
        ll ans=0;
        for(int i=2;i<=sz;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: 35
Accepted
time: 2ms
memory: 9828kb

input:

bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...

output:

5594

result:

ok answer is '5594'

Test #2:

score: 35
Accepted
time: 2ms
memory: 11944kb

input:

bdgfcbabegfbbbgecfbddbaceaefbebgeafdbbgaebebdabgebabacccebbaebeafbefaabdgfcbabegdbaceaefbegcaegagcdgcacccfbbfgffgcdgbccgecbdbcagbbcacccfbbfgeegfcaecbcebebdabgebbbebbgcfafbbbgbdbabgbabfgdfaggfbcbabeebbdaagacgbafecebfccdbgfacgcabefaaedadeacgdeegfcaecbcabacccebbacdbbdceeegcdbbdceeegbaccaecfbgbbebbgcfaf...

output:

7308

result:

ok answer is '7308'

Test #3:

score: 0
Wrong Answer
time: 0ms
memory: 12096kb

input:

baeedcbgaeaabdcaeeagbeffgedegdfcggaeafeegccecbacaaaabdcaeeaggedcbbaebfbcbbbebeaeagedddgabgccdecfeegcababaddfcabcbbbebeaegabeddeedaaabebgcafgeefgeabcaafgcbcfaafgadddgdbccbcddfacfcgdeefgeabcaagbgbgdbefdcefcacafcagcfadegebcababaddfcaffbfgdfecefgafcfgddbagfgceabefcaaebagddabcbbbebeaedaddaacgfcabeffgfgeg...

output:

5793

result:

wrong answer expected '6011', found '5793'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%