用了字符串哈希还是全部RE了,小的样例都对,求大佬看看
查看原帖
用了字符串哈希还是全部RE了,小的样例都对,求大佬看看
1695911
yxc0909楼主2025/7/25 16:21
#include<iostream>
using namespace std;
#include<cstdio>
#include<algorithm>
#include<cstring>
typedef unsigned long long ull;
const int N=10010,P=131;
ull h[N],p[N];
int res[N];
char str[1510];
int n;
int j=0;
ull get(int l,int r)
{
	return h[r]-h[l-1]*p[r-l+1];
}
int main()
{
	scanf("%d",&n);
	p[0]=1;
	while(n--)
	{
		scanf("%s",str+1);
		int i=1;
		for(i=1;str[i]!='\n';i++)
		{
			p[i]=p[i-1]*P;
			h[i]=h[i-1]*P+str[i];
		}
		int cnt=get(1,i-1);
		res[j++]=cnt;
		memset(h,0,sizeof(h));
	}
	j-=1;
	sort(res,res+j);
	cout<<unique(res,res+j)-res<<endl;
	return 0;
}
2025/7/25 16:21
加载中...