WA#10,TLE#9,求助
查看原帖
WA#10,TLE#9,求助
342036
Star_V楼主2023/7/29 17:16
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
char s[3005];
char t[3005];
const ll mods=192608179773;
const ll x=203;
ll res[9000009];
int cnt;
int main()
{
	scanf("%d%s%s",&n,s+1,t+1);
	for(int i=1;i<=n;i++)
	{
		int pos=1;
		ll num=0;
		for(int j=i;j<=n;j++)
		{
			while(pos<=n&&s[pos]!=t[j]) pos++;
			if(pos>n) break;
			pos++;
			num=((ll)num*x+(ll)(t[j]-'a')+1)%mods;
			res[++cnt]=num;
		}
	}
	sort(res+1,res+1+cnt);
	printf("%d",unique(res+1,res+1+cnt)-res-1);
	return 0;
}
2023/7/29 17:16
加载中...