QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#129582 | #801. 回文自动机 | exxqfu# | 0 | 1ms | 5400kb | C++14 | 1.4kb | 2023-07-22 20:56:42 | 2023-07-22 20:56:44 |
Judging History
answer
#include <cstdio>
#define rep(i, d, u) for(int i = d; i <= u; ++i)
#define dep(i, u, d) for(int i = u; i >= d; --i)
int sred(char *st) {
int re = 0;
char ch;
do {
ch = getchar();
} while('z' < ch || ch < 'a');
do {
st[++re] = ch;
} while('a' <= (ch = getchar()) && ch <= 'z');
return re;
}
void lwit(long long da) {
int ch[21], cn = 0;
do {
ch[++cn] = da - da / 10 * 10;
} while(da /= 10);
do {
putchar('0' ^ ch[cn]);
} while(--cn);
}
void dmax(long long &le, long long ri) {
if(le < ri) {
le = ri;
}
}
const int _maxn = 1000011, _maxb = 31;
int slen, sons[_maxn][_maxb], lasn, lens[_maxn], fail[_maxn], coun, dpot[_maxn];
char s[_maxn];
long long rans;
void adds(int at) {
while(lasn && s[at] != s[at - lens[lasn] - 1]) {
lasn = fail[lasn];
}
if(!sons[lasn][s[at] - 'a']) {
lens[sons[lasn][s[at] - 'a'] = ++coun] = lens[lasn] + 2;
int tn = fail[lasn];
while(tn && s[tn] != s[tn - lens[lasn] - 1]) {
tn = fail[tn];
}
if(tn) {
fail[coun] = sons[tn][s[at] - 'a'];
} else {
fail[coun] = 2;
}
}
lasn = sons[lasn][s[at] - 'a'];
}
int main() {
slen = sred(s), lens[fail[coun = 2] = 1] = -1;
rep(i, 1, slen) {
adds(i), ++dpot[lasn];
}
dep(i, coun, 3) {
dpot[fail[i]] += i;
}
rep(i, 3, coun) {
dmax(rans, 1ll * dpot[i] * lens[i] * lens[i]);
}
lwit(rans), putchar('\n');
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5400kb
input:
bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...
output:
3978
result:
wrong answer expected '5594', found '3978'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%