虽然内存已经控制在 40MB 以内,但是我想再优化一下。
题解上使用了 sort 的做法,我也了解了。
WA:91pts(P=268435399, Q=997777771)
#include <iostream>
#include <string>
using namespace std;
long N, cnt = 0;
bool exist[805306368];//质数为805306357, 2147483647
string strs;
unsigned long Hash(string str) {
unsigned long Hash_res = 0x811c9dc5, len = str.size();
for(int i = 0; i < len; i++)
{
Hash_res *= 0x1000193;
Hash_res = (Hash_res ^ (unsigned long)str[i]) % 2147483647;
}
return Hash_res % 805306357;
}
int main(){
cin >> N;
for(int i = 0; i < N; i++)
{
cin >> strs;
if(!exist[Hash(strs)])
cnt++,
exist[Hash(strs)] = 1;
}
cout << cnt << endl;
return 0;
}