QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#9733#801. 回文自动机Qingyu0 2ms13820kbC++201.7kb2021-04-09 22:50:382021-12-19 11:45:57

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2021-12-19 11:45:57]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:13820kb
  • [2021-04-09 22:50:38]
  • 提交

answer

#include <bits/stdc++.h>

const int N = 4e6 + 50;
int len[N], fa[N], ch[N][26], cnt[N], p, tot, lst;
char s[N];

inline void init()
{
	s[0] = '$';
	tot = -1;
	len[++tot] = 0, len[++tot] = -1;
	fa[0] = 1;
}

inline int get_fail(int x)
{
	while (s[p] != s[p - len[x] - 1]) x = fa[x];
	return x;
}

inline void ins(int x)
{
	int o = get_fail(lst);
	if (!ch[o][x])
	{
		++tot;
		len[tot] = len[o] + 2;
		fa[tot] = ch[get_fail(o)][x];
		ch[o][x] = tot;
	}
	lst = ch[o][x];
	++cnt[lst];
}

template<int T>
struct fast_io
{
	char p[T], *p1, *p2, q[T], *q1, *q2;
	fast_io()
	{
		p1 = p2 = p, q1 = q, q2 = q + T;
	}
	inline char gc()
	{
		return p1 == p2 && (p2 = (p1 = p) + fread(p, 1, T, stdin), p1 == p2) ? EOF : *p1 ++;
	}
	inline void pc(char c)
	{
		if (q1 == q2)
		{
			fwrite(q, 1, T, stdout);
			q1 = q;
		}
		*q1++ = c;
	}
	~fast_io()
	{
		fwrite(q, 1, q1 - q, stdout);
	}
};
fast_io<1024768> io;

inline int read()
{
	int res = 0;
	char ch;
	do ch = io.gc(); while (ch < 48 || ch > 57);
	do res = res * 10 + ch - 48, ch = io.gc(); while (ch >= 48 && ch <= 57);
	return res;
}

inline void putint(int64_t x)
{
	if (x < 0) x = -x;
	if (x >= 10) putint(x / 10);
	io.pc(48 + x % 10);
}

inline void output(int64_t x, char ch = ' ')
{
	putint(x);
	io.pc(ch);
}

int main()
{
	scanf("%s", s + 1);
	init();
	int n = strlen(s + 1);
	for (int i = 1; i <= n; ++i)
	{
		p = i;
		ins(s[i] - 'a');
	}
	long long ans = 0;
	for (int i = tot; i >= 1; --i)
	{
		cnt[fa[i]] += cnt[i];
	}
	for (int i = 1; i <= tot; ++i)
		ans = std::max(ans, 1ll * len[i] * len[i] * cnt[i]);
	output(ans);
	return 0;
}

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: 13820kb

input:

bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbeffcfgfeedgegdagbgagafbfaaffgfaaebcecfdfccdfdfbefdgddadgagbbefebcecfdfccdegecadfebffgcedfcdcdaaeadeebcedbdagcaagdgcdfbabafbdebgacaabdegecadfebebdbfgegadabbfgeacdgdcgaefccebfeddacbabfeecgbcecegeaabcbdafa...

output:

3978 

result:

wrong answer expected '5594', found '3978'

Subtask #2:

score: 0
Skipped