QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#64752 | #801. 回文自动机 | zhoukangyang# | 0 | 4ms | 9636kb | C++11 | 1.0kb | 2022-11-25 15:02:54 | 2022-11-25 15:02:57 |
Judging History
answer
#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define vi vector < int >
#define sz(a) ((int) (a).size())
#define me(a, x) memset(a, x, sizeof(a))
using namespace std;
const int N = 2e6 + 7;
int n, m;
char s[N];
int p, ch[N][26], len[N], fa[N], lst, tot = 1;
int getfa(int x) {
for(; p - len[x] - 1 < 1 || s[p - len[x] - 1] != s[p]; x = fa[x]) ;
return x;
}
void ins() {
lst = getfa(lst);
if(!ch[lst][s[p] - 'a'])
++tot,
fa[tot] = ch[lst][s[p] - 'a'],
len[tot] = len[lst] + 2,
ch[lst][s[p] - 'a'] = tot;
lst = ch[lst][s[p] - 'a'];
}
int cnt[N];
int main() {
ios :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> (s + 1);
n = strlen(s + 1);
fa[0] = 1, len[1] = -1;
L(i, 1, n)
p = i, ins(), cnt[lst] += 1;
R(i, tot, 1)
cnt[fa[i]] += cnt[i];
ll ns = 0;
L(i, 2, tot)
ns = max(ns, (ll) cnt[i] * len[i] * len[i]);
cout << ns << '\n';
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 9636kb
input:
bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...
output:
3978
result:
wrong answer expected '5594', found '3978'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%