字符串哈希部分MLE?
查看原帖
字符串哈希部分MLE?
1086906
Eric_dong楼主2025/7/30 14:21

https://www.luogu.com.cn/record/227775851

#include <bits/stdc++.h>
using namespace std;

const int N = 1e4 + 10,P = 13331;
string s[N];
unsigned long long h[N][N],p[N];

int main(){
	int n;
	cin>>n;
	for(int i = 1;i <= n;i ++){
		string x; 
		cin>>x; 
		s[i] = x.substr(1);
	}
	p[0] = 1;
	for(int i = 1;i <= 1500;i ++){
		p[i] = p[i-1] * P;
	}
	
	for(int i = 1;i <= n;i ++){
		for(int j = 1;j <= s[i].size();j ++){
			h[i][j] = h[i][j-1] * P + s[i][j];
		}
	}
	set<unsigned long long> a;
	for(int i = 1;i <= n;i ++){
		a.insert(h[i][s[i].size()]);
	}
	cout<<a.size();
	return 0;
}
2025/7/30 14:21
加载中...