QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#341802#801. 回文自动机Unreality#0 1ms5916kbC++142.0kb2024-02-29 21:30:582024-02-29 21:31:00

Judging History

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

  • [2024-02-29 21:31:00]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:5916kb
  • [2024-02-29 21:30:58]
  • 提交

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%