QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#721623#5312. Levenshtein DistancemasonpopWA 1ms5824kbC++141.9kb2024-11-07 16:29:222024-11-07 16:29:22

Judging History

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

  • [2024-11-07 16:29:22]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5824kb
  • [2024-11-07 16:29:22]
  • 提交

answer

// ubsan: undefined
// accoders
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
const int maxn=5e4+10;
const int maxm=65;
const int D=30;
const ull B=131;
int lim,n,m,f[maxm][maxm],ans[maxm],M,L[maxn][maxm];
char s[maxn],t[maxn],tmp[maxn];
ull pw[maxn],H[2][maxn];
inline ull get(int l,int r,int id)
{
	return H[id][r]-H[id][l-1]*pw[r-l+1];
}
inline int LCP(int x,int y)
{
	if(x<0 || x>n || y<0 || y>m)return 0;
	int l=1,r=min(n-x+1,m-y+1),res=0;
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if(get(x,x+mid-1,0)==get(y,y+mid-1,1))res=mid,l=mid+1;
		else r=mid-1;
	}
	return res;
}
inline void chkmax(int &a,int b){a=max(a,b);}
int main()
{
	scanf("%d",&lim);
	scanf("%s",s+1);scanf("%s",t+1);
	n=strlen(s+1);m=strlen(t+1);
	pw[0]=1;
	for(int i=1;i<=max(n,m);i++)pw[i]=pw[i-1]*B;
	for(int i=1;i<=n;i++)H[0][i]=H[0][i-1]*B+s[i]-'a'+1;
	for(int i=1;i<=m;i++)H[1][i]=H[1][i-1]*B+t[i]-'a'+1;
	for(int i=0;i<=n;i++)
	{
		for(int j=max(i-D,0);j<=min(i+D,m);j++)L[i][j-i+D]=LCP(i+1,j+1);
	}
	for(int st=1;st<=m;st++)
	{
		//printf("st %d\n",st);
		M=m-st+1;
		for(int j=st;j<=m;j++)tmp[j-st+1]=t[j];
		memset(f,0xcf,sizeof(f));f[0][D]=0;
		for(int i=0;i<=lim;i++)
		{
			for(int j=-D;j<=D;j++)
			{
				if(f[i][j+D]<0)continue;
				int pos=f[i][j+D];
				//printf("pos1:%d,pos2:%d,lcp:%d\n",pos,pos+j+st-1,L[pos][j+(st-1)+D]);
				if(pos>0 && pos<n && pos+st+j>0 && pos+st+j<=m)f[i][j+D]+=L[pos][j+(st-1)+D];
				if(i!=lim)
				{
					chkmax(f[i+1][j-1+D],f[i][j+D]+1);
					chkmax(f[i+1][j+1+D],f[i][j+D]);
					chkmax(f[i+1][j+D],f[i][j+D]+1);
				}
			}
		}
        //printf("f:%d\n",f[1][-1+D]);
		for(int j=-D;j<=D;j++)
		{
			for(int i=0;i<=lim;i++)
			{
				if(n+j<=0 || n+j>(m-st+1) || f[i][j+D]<n)continue;
				//printf("i %d,j %d\n",i,j);
				ans[i]++;break;
			}
		}
	}
	for(int i=0;i<=lim;i++)printf("%d\n",ans[i]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5824kb

input:

4
aaa
aabbaab

output:

0
3
12
10
2

result:

wrong answer 2nd numbers differ - expected: '5', found: '3'