样例过了,全WA
查看原帖
样例过了,全WA
1218883
yanghb666楼主2025/7/23 17:49
#include <bits/stdc++.h>
using namespace std;
int nx[10000010], num[10000010], n, ans;
int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    while (n --) {
    	memset(nx, 0, sizeof nx);
    	memset(num, 0, sizeof num);
    	num[1] = ans = 1;
    	string s;
    	cin >> s;
    	s = " " + s;
    	for (int i = 2, j = 0; i < s.length(); i ++) {
    		while (j && s[i] != s[j + 1])
    			j = nx[j];
    		if (s[i] == s[j + 1])
    			j ++;
    		nx[i] = j;
    		num[i] = num[j] + 1;
		}
		for (int i = 2, j = 0; i < s.length(); i ++) {
			while (j && s[i] != s[j + 1])
				j = nx[j];
			if (s[i] == s[j + 1])
				j ++;
			while (j * 2 > i)
				j = nx[j];
			ans = ans * (num[j] + 1) % 1000000007;
		}
		cout << ans << endl;
	}
    return 0;
}
2025/7/23 17:49
加载中...