QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#762893#5312. Levenshtein DistancehighkjWA 0ms4048kbC++202.2kb2024-11-19 17:09:422024-11-19 17:09:49

Judging History

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

  • [2024-11-19 17:09:49]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4048kb
  • [2024-11-19 17:09:42]
  • 提交

answer

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define rep(i,x,y) for(register int i=x;i<=y;i++)
#define rep1(i,x,y) for(register int i=x;i>=y;--i)
#define fire signed
#define il inline
template<class T> il void print(T x) {
	if(x<0) printf("-"),x=-x;
	if (x > 9) print(x / 10);
	putchar(x % 10 + '0');
}
const int bufsize = 230005;
char buf[bufsize], *f1, *f2;
#define getchar() (f1 == f2 && (f2 = buf + fread(f1 = buf, 1, bufsize, stdin)) == buf? EOF: *f1++)
template<class T> il void in(T &x) {
    x = 0; char ch = getchar();
    int f = 1;
    while (ch < '0' || ch > '9') {if(ch=='-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); }
    x *= f;
}
#define ull unsigned long long
int T=1;
const int N=1e5+10;
const int M=32;
long long f[M][M+M];
int k;
string s,t;
const int ba=131;
ull ha[N],ha1[N],jc[N];
int n,m;
ull has(int l,int r) {
	return ha[r]-ha[l-1]*jc[r-l+1];
}
ull has1(int l,int r) {
	return ha1[r]-ha1[l-1]*jc[r-l+1];
}
int lcp(int x,int y) {
	int l=0,r=min(n-x+1,m-y+1),res=0;
	while(l<=r) {
		int mid=l+r>>1;
		if(has(x,x+mid-1)==has1(y,y+mid-1)) l=mid+1,res=mid;
		else r=mid-1;
	}
	return res;
}
int ans[N];
fire main() {
	jc[0]=1;
	in(k);
	cin>>s;
	cin>>t;
	s=" "+s;
	t=" "+t;
	n=s.size()-1;
	m=t.size()-1; 
	rep(i,1,max(n,m)) jc[i]=jc[i-1]*ba;
	rep(i,1,n) ha[i]=ha[i-1]*ba+s[i]-'a'+1;
	rep(i,1,m) ha1[i]=ha1[i-1]*ba+t[i]-'a'+1;
	rep(le,1,m) {
		memset(f,0,sizeof f);
		f[0][M]=lcp(1,le);
		rep(nowk,0,k) {
			rep(l,-nowk,nowk) {
				int len1=f[nowk][l+M],len2=len1+l+le-1;
				f[nowk+1][l+M]=max(f[nowk+1][l+M],f[nowk][l+M]+lcp(len1+2,len2+2)+1);
				f[nowk+1][l+M-1]=max(f[nowk+1][l+M-1],f[nowk][l+M]+lcp(len1+2,len2+1)+1);
				f[nowk+1][l+M+1]=max(f[nowk+1][l+M+1],f[nowk][l+M]+lcp(len1+1,len2+2));
			}
		}
		rep(l,max(1-n,-k),min(k,m-le+1-n)) {
			rep(nowk,0,k) {
				if(f[nowk][l+M]>=n) {
					ans[nowk]++;
					break;
				}
			}
		}
	}
	rep(i,0,k) {
//		ans[i]+=ans[i-1];
		printf("%d\n",ans[i]);
	}
	return false;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 4048kb

input:

4
aaa
aabbaab

output:

0
0
0
0
0

result:

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