QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#341802 | #801. 回文自动机 | Unreality# | 0 | 1ms | 5916kb | C++14 | 2.0kb | 2024-02-29 21:30:58 | 2024-02-29 21:31:00 |
answer
#include <bits/stdc++.h>
using namespace std;
#define _rep(i_,a_,b_) for(int i_ = (a_); i_ <= (b_); ++i_)
#define mid ((L+R) >> 1)
#define multiCase() int testCnt = in(); _rep(curCase,1,testCnt)
#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif
using ll = long long;
using pii = pair<int,int>;
int in(void) { int x; scanf("%d", &x); return x; } ll inl(void) { ll x; scanf("%lld", &x); return x; }
void out(int x) { printf("%d ", x); } void outln(int x) { printf("%d\n", x); }
void out(ll x) { printf("%lld ", x); } void outln(ll x) { printf("%lld\n", x); }
template<typename T> void chkmax(T &a, const T &b) { a = max(a, b); }
template<typename T> void chkmin(T &a, const T &b) { a = min(a, b); }
const int kN = 100500;
int ch[kN][26], fail[kN], len[kN], nc, last, cnt[kN], cnt2[kN], ord[kN];
char s[kN];
void init(void) {
fail[0] = fail[1] = 1, len[1] = -1;
nc = 1, last = 0;
}
int getfail(int x, int i) {
while(s[i] != s[i - len[x] - 1]) x = fail[x];
return x;
}
void extend(int i) {
int y = getfail(last, i);
if(!ch[y][s[i] - 'a']) {
int cur = ++nc; len[cur] = len[y] + 2; fail[cur] = getfail(fail[y], i);
ch[y][s[i] - 'a'] = cur;
} last = ch[y][s[i] - 'a'];
}
int main() {
init();
scanf("%s", s + 1);
int n = strlen(s + 1);
_rep(i,1,n) extend(i), ++cnt[last];
_rep(i,2,nc) ++cnt2[len[i]];
_rep(i,1,n) cnt2[i] += cnt2[i - 1];
_rep(i,2,nc) ord[cnt2[len[i]]--] = i;
ll ans = 0;
for(int i = nc; i > 1; --i) {
int u = ord[i];
chkmax(ans, 1ll * cnt[u] * len[u] * len[u]);
cnt[fail[u]] += cnt[u];
}
outln(ans);
return 0;
}
/*
a list of keywords
clear empty push_back pop_back push pop top front back
emplace_back emplace push_front pop_front insert erase
find count set reset bitset map vector string multiset
first second iterator prev next deque multimap reverse
sort begin end list modify query init check calc prime
putchar getchar puts scanf printf max min swap replace
make_pair make_tuple numeric_limits auto function null
*/
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5916kb
input:
bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...
output:
4552
result:
wrong answer expected '5594', found '4552'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%