QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#290663#6234. 动物园MoRanSky100 ✓444ms90732kbC++23918b2023-12-25 06:20:412023-12-25 06:20:41

Judging History

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

  • [2023-12-25 06:20:41]
  • 评测
  • 测评结果:100
  • 用时:444ms
  • 内存:90732kb
  • [2023-12-25 06:20:41]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <cstring>
#define rint register int
using namespace std;
typedef long long LL;
const int N = 1000005, L = 20, P = 1e9 + 7;
int n, nxt[N], dep[N], fa[N][L];
char s[N];
int inline get(int x) {
	int l = x / 2;
	for (rint i = L - 1; ~i; i--)
		if (fa[x][i] > l) x = fa[x][i];
	return dep[fa[x][0]];
}
int main() {
	int T; scanf("%d", &T);
	while (T--) {
		memset(fa, 0, sizeof fa);
		scanf("%s", s + 1);
		n = strlen(s + 1);
		dep[1] = 1;
		for (rint i = 2, j = 0; i <= n; i++) {
			while (j && s[i] != s[j + 1]) j = nxt[j];
			if (s[i] == s[j + 1]) j++;
			// j -> i
			nxt[i] = j;
			dep[i] = dep[j] + 1, fa[i][0] = j;
			for (rint j = 1; j < L && fa[i][j - 1]; j++) 
				fa[i][j] = fa[fa[i][j - 1]][j - 1];
		}
		int ans = 1;
		for (rint i = 1; i <= n; i++) 
			ans = (LL)ans * (get(i) + 1) % P;
		printf("%d\n", ans);
	}
	return 0;
}	

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 10
Accepted
time: 21ms
memory: 85972kb

input:

5
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaxpuvf
abababababababababababababababababababababababdgcd
abcbaabcbaabcbaabcbaabcbaabcbaabcbaabcbaabcbafmlqh
abacababacababacababacababacababacababacababadjyxq
aabaacaabaacaabaacaabaacaabaacaabaacaabaacaabjtaxw

output:

592345761
371390093
121623872
675691877
481106999

result:

ok 5 number(s): "592345761 371390093 121623872 675691877 481106999"

Test #2:

score: 10
Accepted
time: 27ms
memory: 84096kb

input:

5
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaavtgynkaevpdhsdwswilx
ababababababababababababababababababababababababababababababababababababababababababababababababa...

output:

469770619
76547694
933305750
902388437
803348921

result:

ok 5 number(s): "469770619 76547694 933305750 902388437 803348921"

Test #3:

score: 10
Accepted
time: 25ms
memory: 84348kb

input:

5
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaafcbwqryehhjfnlhglcnn
ababababababababababababababababababababababababababababababababababababababababababababababababa...

output:

734885313
42387799
866611493
737798559
606697835

result:

ok 5 number(s): "734885313 42387799 866611493 737798559 606697835"

Test #4:

score: 10
Accepted
time: 27ms
memory: 85748kb

input:

5
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

256900524
822524261
413461597
106784584
900200874

result:

ok 5 number(s): "256900524 822524261 413461597 106784584 900200874"

Test #5:

score: 10
Accepted
time: 22ms
memory: 85844kb

input:

5
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

338653171
215976943
353365401
126668510
374446639

result:

ok 5 number(s): "338653171 215976943 353365401 126668510 374446639"

Test #6:

score: 10
Accepted
time: 59ms
memory: 84592kb

input:

5
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

121054060
135829705
586084763
774583391
672914918

result:

ok 5 number(s): "121054060 135829705 586084763 774583391 672914918"

Test #7:

score: 10
Accepted
time: 90ms
memory: 86028kb

input:

5
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

608896507
705745581
866882032
907283717
280168955

result:

ok 5 number(s): "608896507 705745581 866882032 907283717 280168955"

Test #8:

score: 10
Accepted
time: 205ms
memory: 89056kb

input:

5
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

757739184
436599146
408735068
62286478
824797798

result:

ok 5 number(s): "757739184 436599146 408735068 62286478 824797798"

Test #9:

score: 10
Accepted
time: 440ms
memory: 90668kb

input:

5
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

359993524
770772317
946742907
673664964
798002419

result:

ok 5 number(s): "359993524 770772317 946742907 673664964 798002419"

Test #10:

score: 10
Accepted
time: 444ms
memory: 90732kb

input:

5
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

237665674
899763767
416501680
103496894
979807695

result:

ok 5 number(s): "237665674 899763767 416501680 103496894 979807695"

Extra Test:

score: 0
Extra Test Passed