QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#91934 | #801. 回文自动机 | Yansuan_HCl# | 0 | 2ms | 7940kb | C++14 | 990b | 2023-03-29 22:36:01 | 2023-03-29 22:36:03 |
Judging History
answer
#include <bits/stdc++.h>
#define ms(x, v) memset(x, v, sizeof(x))
#define il __attribute__((always_inline)) static
#define U(i,l,r) for(int i(l),END##i(r);i<=END##i;++i)
#define D(i,r,l) for(int i(r),END##i(l);i>=END##i;--i)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
template <class T> using BS = basic_string<T>;
#define meow(...) fprintf(stderr, __VA_ARGS__)
const int N = 1000006;
char s[N]; int n, len[N], ch[N][26], fail[N], cnt[N], m;
ll ans;
int main() {
scanf("%s", s + 1); n = strlen(s + 1);
len[1] = -1; fail[0] = 1; m = 1; int p = 0;
U (i, 1, n) {
char c = s[i], d = s[i] - 'a';
while (c != s[i - len[p] - 1]) p = fail[p];
if (!ch[p][d]) {
len[++m] = len[p] + 2;
int j = p;
while (c != s[i - len[j] - 1]) j = fail[j];
fail[m] = ch[j][d];
ch[p][d] = m;
}
p = ch[p][d];
++cnt[p];
}
U (i, 1, m)
ans = max(ans, ll(len[i]) * len[i] * cnt[i]);
printf("%lld", ans);
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 7940kb
input:
bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...
output:
3978
result:
wrong answer expected '5594', found '3978'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%