为什么用set过不了,用unordered_set能过
查看原帖
为什么用set过不了,用unordered_set能过
1132005
Contingency_Core楼主2024/8/2 20:57

RT
unordered_set
set

#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <queue>
#include <cstdio>
#include <map>
#include <vector>
#include <list>
#include <functional>
#include <stack>
#include <unordered_map>
#include <set>
#include <cctype>
#include <cstring>
#include <bitset>
#include <unordered_set>
#define m(a,b) make_pair(a,b)
#define F first
#define S second
#define us unsigned short
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define XOR(a,b) ((a&&!b)||(!a&&b))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int M=1e9,N=3003;const ll LM=1e18,P=1331;int YI=1,LING=0;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr),cout.tie(nullptr);
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	string s1,s2;
	int n,now;
	/*unordered_*/set <ull> se;
	ull h[N],miP[N],ch;
	cin>>n;
	//se.reserve(n*n*1.5);
	cin>>s1>>s2;
	h[0]=s2[0]-'a'+12;
	miP[0]=1;
	for(int i=1;i<n;i++)
	{
		h[i]=h[i-1]*P+s2[i]-'a'+12;
		miP[i]=miP[i-1]*P;
	}
	for(int i=0;i<n;i++)
	{
		now=i;
		for(int ii=0;ii<n;ii++)
		{
			if(s1[ii]==s2[now])
			{
				ch=h[now]-h[i-1]*miP[now-i+1];
				se.insert(ch);
				now++;
			}
		}
	}
	cout<<se.size();
	return 0;
}

不光TLE(O(n^2logn)应该不会TLE啊),还有WA(???)。

2024/8/2 20:57
加载中...