为什么?
查看原帖
为什么?
538209
copper_ingot楼主2024/7/29 15:40

显示 Wrong Answer.wrong answer 1st lines differ - expected: '3', found: '-4294967293',搞不懂为啥

#include <bits/stdc++.h>
using namespace std;
char str[100004]; int n, fail[100001], f[100001];
vector<int> ans;
int main(){
	scanf("%s", str + 1); n = strlen(str + 1);
	for (int i = 2; i <= n; i++){
		int j = fail[i - 1];
		while (j && str[i] != str[j + 1]) j = fail[j];
		if (str[i] == str[j + 1]) j++;
		fail[i] = j;
	}
	for (int i = fail[n]; i; i = fail[i]) ans.push_back(i);
	for (int i = n; i >= 1; i--){++f[i]; f[fail[i]] += f[i];}
	printf("%lld\n", ans.size() + 1);
	for (int i = 0; i < ans.size(); i++){
		int k = ans[i];
		if (k > 2147483647) puts("aaaaaaaaaaaa");
		printf("%lld %lld\n", k, f[k]);
	}
	printf("%lld %lld\n", n, f[n]);
	return 0;
}
2024/7/29 15:40
加载中...