QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#730246#5312. Levenshtein DistanceerduolongRE 0ms0kbC++142.0kb2024-11-09 19:24:362024-11-09 19:24:38

Judging History

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

  • [2024-11-09 19:24:38]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-09 19:24:36]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef unsigned long long ULL;
const int N=1e5+10,M=65,V=30,P=131;
ULL p[N],hs[N],ht[N];
char S[N],T[N];
int f[M][M],g[N];
int Lcp[N][M];
int ans[N];
int n,m;
int k;

ULL get_S(int l,int r)
{
	return hs[r]-hs[l-1]*p[r-l+1];
}

ULL get_T(int l,int r)
{
	return ht[r]-ht[l-1]*p[r-l+1];
}

int lcp(int i,int j)
{
	int b=j-i+k;
//	if(b<0) assert(0);
//	if(~Lcp[i][b]) return Lcp[i][b];
	int l=1,r=min(n-i+1,m-j+1),ans=0;
	while(l<=r)
	{
		int mid=l+r>>1;
		if(get_S(i,i+mid-1)==get_T(j,j+mid-1)) ans=mid,l=mid+1;
		else r=mid-1;
	}
	return ans;
//	printf("lcp: %d %d %d\n",i,j,ans);
//	return Lcp[i][b]=ans;
}

signed main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	
	
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	
	for(int i=(p[0]=1);i<N;i++) p[i]=p[i-1]*P;
	cin>>k;
	cin>>(S+1);
	n=strlen(S+1);
	for(int i=1;i<=n;i++) hs[i]=hs[i-1]*P+S[i];
	cin>>(T+1);
	m=strlen(T+1);
	for(int i=1;i<=m;i++) ht[i]=ht[i-1]*P+T[i];
	
	memset(Lcp,-1,sizeof Lcp);
	
	for(int i=1;i<=m;i++)
	{
//		printf("solve: %d:\n",i);
		memset(f,-0x3f,sizeof f);
		f[0][k]=0;
		for(int t=0;t<=k;t++)
		{
			for(int j=-k,_j=0;j<=k;j++,_j++)
			{
				if(f[t][_j]<0) continue;
				int &x=f[t][_j];
				x+=lcp(x+1,i+x+j);
//				printf("[%d %d %d]\n",t,j,x);
				if(x+1<=n && i+x+j<=m) f[t+1][_j]=max(f[t+1][_j],x+1);//m
				if(i+x+j<=m) f[t+1][_j+1]=max(f[t+1][_j+1],x);//d
				if(x+1<=n) f[t+1][_j-1]=max(f[t+1][_j-1],x+1);//a
			}
		}
		int L=max(i,i-1+n-2*k),R=min(m,i-1+n+2*k);
		for(int x=L;x<=R;x++) g[x]=k+1;
		for(int j=-k,_j=0;j<=k;j++,_j++)
		{
			for(int t=0;t<=k;t++)
			{
				if(f[t][_j]>=n) 
				{
					g[i-1+n+j]=t;
					break;
				}
			}
		}
		
//		for(int x=L;x<=R;x++) cout<<g[x]<<" ";
//		cout<<"\n";
		
		for(int x=L;x<R;x++) g[x+1]=min(g[x+1],g[x]+1);
		for(int x=R;x>L;x--) g[x-1]=min(g[x-1],g[x]+1);
		for(int x=L;x<=R;x++) ans[g[x]]++;
	}
	
	for(int i=0;i<=k;i++) cout<<ans[i]<<"\n";
	
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

4
aaa
aabbaab

output:


result: