QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#724191#5312. Levenshtein DistanceThe_Shadow_DragonRE 1016ms17060kbC++143.1kb2024-11-08 10:40:472024-11-08 10:40:48

Judging History

你现在查看的是最新测评结果

  • [2024-11-08 10:40:48]
  • 评测
  • 测评结果:RE
  • 用时:1016ms
  • 内存:17060kb
  • [2024-11-08 10:40:47]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ull unsigned long long
#define sort stable_sort 
#define endl '\n'
int f[40][70],ans[40];
char s[50010],t[50010],tmp[100010];
struct SA
{
	struct ST
	{
		int fminn[100010][25];
		void init(int n,int a[])
		{
			memset(fminn,0x3f,sizeof(fminn));
			for(int i=1;i<=n;i++)
			{
				fminn[i][0]=a[i]; 
			}
			for(int j=1;j<=log2(n);j++)
			{
				for(int i=1;i+(1<<j)-1<=n;i++)
				{
					fminn[i][j]=min(fminn[i][j-1],fminn[i+(1<<(j-1))][j-1]);
				}
			}
		}
		int query(int l,int r)
		{
			if(l>r)
			{
				swap(l,r);
			}
			l++;
			int t=log2(r-l+1);
			return min(fminn[l][t],fminn[r-(1<<t)+1][t]);
		}
	}T;
	int sa[100010],rk[200010],oldrk[200010],id[100010],cnt[100010],key[100010],height[100010];
	int val(char x)
	{
		return (int)x;
	}
	void counting_sort(int n,int m)
	{
		memset(cnt,0,sizeof(cnt));
		for(int i=1;i<=n;i++)
		{
			cnt[key[i]]++;
		}
		for(int i=1;i<=m;i++)
		{
			cnt[i]+=cnt[i-1];
		}
		for(int i=n;i>=1;i--)
		{
			sa[cnt[key[i]]]=id[i];
			cnt[key[i]]--;
		}
	}
	void init(char s[],int len)
	{
		int m=127,tot=0,num=0;
		for(int i=1;i<=len;i++)
		{
			rk[i]=val(s[i]);
			id[i]=i;
			key[i]=rk[id[i]];
		}
		counting_sort(len,m);
		for(int w=1;tot!=len;w<<=1,m=tot)
		{
			num=0;
			for(int i=len;i>=len-w+1;i--)
			{
				num++;
				id[num]=i;
			}
			for(int i=1;i<=len;i++)
			{
				if(sa[i]>w)
				{
					num++;
					id[num]=sa[i]-w;
				}
			}
			for(int i=1;i<=len;i++)
			{
				key[i]=rk[id[i]];
			}
			counting_sort(len,m);
			for(int i=1;i<=len;i++)
			{
				oldrk[i]=rk[i];
			}
			tot=0;
			for(int i=1;i<=len;i++)
			{
				tot+=(oldrk[sa[i]]!=oldrk[sa[i-1]]||oldrk[sa[i]+w]!=oldrk[sa[i-1]+w]);
				rk[sa[i]]=tot;
			}
		}
		for(int i=1,j=0;i<=len;i++)
		{
			j-=(j>=1);
			while(s[i+j]==s[sa[rk[i]-1]+j])
			{
				j++;
			}
			height[rk[i]]=j;
		}
		T.init(len,height);
	}
	int lcp(int x,int y)
	{
		return T.query(rk[x],rk[y]);
	}
}S;
int main()
{
	int k,lens,lent,i,j,h;
	cin>>k>>(s+1)>>(t+1);
	lens=strlen(s+1);
	lent=strlen(t+1);
	for(i=1;i<=lens;i++)
	{
		tmp[i]=s[i];
	}
	tmp[lens+1]='&';
	for(i=1;i<=lent;i++)
	{
		tmp[lens+1+i]=t[i];
	}
	S.init(tmp,lens+1+lent);
	for(h=1;h<=lent;h++)
	{	
		memset(f,-0x3f,sizeof(f));
		f[0][k]=0;
		for(i=0;i<=k;i++)
		{
			for(j=-k;j<=k;j++)
			{
				if(f[i][j+k]>=0&&f[i][j+k]+j>=0&&f[i][j+k]+j+h-1<=lent)
				{
					if(f[i][j+k]+1<=lens&&f[i][j+k]+j+1+h-1+lens+1<=lens+1+lent)
					{
						f[i][j+k]+=S.lcp(f[i][j+k]+1,f[i][j+k]+j+1+h-1+lens+1);
					}
					if(j-1+k>=0)
					{
						f[i+1][j-1+k]=max(f[i+1][j-1+k],f[i][j+k]+(f[i][j+k]!=lens));
					}
					f[i+1][j+k]=max(f[i+1][j+k],f[i][j+k]+(f[i][j+k]!=lens));
					f[i+1][j+1+k]=max(f[i+1][j+1+k],f[i][j+k]);
				}
			}
		}
		for(j=-k;j<=k;j++)
		{
			for(i=0;i<=k;i++)
			{
				if(f[i][j+k]==lens&&lens+j>0&&lens+j+h-1<=lent)
				{
					ans[i]++;
					break;
				}
			}
		}
	}
	for(i=0;i<=k;i++)
	{
		cout<<ans[i]<<endl;
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 16628kb

input:

4
aaa
aabbaab

output:

0
5
15
7
1

result:

ok 5 number(s): "0 5 15 7 1"

Test #2:

score: 0
Accepted
time: 1016ms
memory: 17060kb

input:

30
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

ok 31 numbers

Test #3:

score: -100
Runtime Error

input:

30
BBAAABAABBBA
ABBABBBBAABAAAABABBBAABAABBAABAAAAAABAABABBAAAABAAAAABABAABAABBABBAAAABBBBAABBABAAABAABAABBBBBABBABABBBBABBBBAAABBABABBBBAAABBBBAAAABABABABABABABAAABBBBBAABAABAABBAABBBAABBBBBBBABAABAABAABABAABAAABAABBBAABABBABBAAABAAAABABABBABBBAAABBBAAAABBBBABABABAABAABBBBBBBBBAABBBABABBBABAABBABBA...

output:


result: