QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#129582#801. 回文自动机exxqfu#0 1ms5400kbC++141.4kb2023-07-22 20:56:422023-07-22 20:56:44

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-22 20:56:44]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:5400kb
  • [2023-07-22 20:56:42]
  • 提交

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;
}

Details

Tip: Click on the bar to expand more detailed information

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%