QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#763241#5312. Levenshtein DistancehighkjWA 1652ms141988kbC++111.9kb2024-11-19 19:08:522024-11-19 19:08:53

Judging History

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

  • [2024-11-19 19:08:53]
  • 评测
  • 测评结果:WA
  • 用时:1652ms
  • 内存:141988kb
  • [2024-11-19 19:08:52]
  • 提交

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');
}
#define ull unsigned long long
int T=1;
const int N=1e5+10;
const int M=32;
int f[M][M+M];
int k;
string s,t;
const int ba=131;
ull ha[N],ha1[N],jc[N];
int n,m;
gp_hash_table<int,int>mp[N];
il int lcp(int x,int y) {
	if(mp[x][y]||s[x]!=t[y]) {
		return mp[x][y];
	}
	int l=0,r=min(n-x+1,m-y+1),res=0;
	while(l<=r) {
		int mid=l+r>>1;
		if(ha[x+mid-1]-ha[x-1]*jc[mid]==ha1[y+mid-1]-ha1[y-1]*jc[mid]) l=mid+1,res=mid;
		else r=mid-1;
	}
	mp[x][y]=res;
	return res;
}
int ans[N];
fire main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	jc[0]=1;
	cin>>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) {
		rep(nowk,0,k) rep(l,-nowk,nowk) f[nowk][l+M]=false;
//		f[0][M]=lcp(1,le);
		rep(nowk,0,k-1) {
			rep(l,-nowk,nowk) {
				int len1=f[nowk][l+M],len2=len1+l+le-1;
				f[nowk][l+M]+=lcp(len1+1,len2+1);
				f[nowk+1][l+M]=max(f[nowk+1][l+M],f[nowk][l+M]+1);
				f[nowk+1][l+M-1]=max(f[nowk+1][l+M-1],f[nowk][l+M]+1);
				f[nowk+1][l+M+1]=max(f[nowk+1][l+M+1],f[nowk][l+M]);
			}
		}
		rep(l,max(1-n,-k),min(k,m-le+1-n)) {
			rep(nowk,0,k) {
//				int len1=f[nowk][l+M],len2=len1+l+le-1;
//				f[nowk][l+M]+=lcp(len1+1,len2+1);
				if(f[nowk][l+M]>=n) {
					ans[nowk]++;
					break;
				}
			}
		}
	}
	rep(i,0,k) printf("%d\n",ans[i]);
	return false;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 26436kb

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: 1652ms
memory: 117764kb

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
Wrong Answer
time: 580ms
memory: 141988kb

input:

30
BBAAABAABBBA
ABBABBBBAABAAAABABBBAABAABBAABAAAAAABAABABBAAAABAAAAABABAABAABBABBAAAABBBBAABBABAAABAABAABBBBBABBABABBBBABBBBAAABBABABBBBAAABBBBAAAABABABABABABABAAABBBBBAABAABAABBAABBBAABBBBBBBABAABAABAABABAABAAABAABBBAABABBABBAAABAAAABABABBABBBAAABBBAAAABBBBABABABAABAABBBBBBBBBAABBBABABBBABAABBABBA...

output:

17
662
8230
50302
166666
310121
345469
280387
227200
209178
203013
198561
105117
102147
99771
97730
96058
94730
93633
92720
92060
91525
91143
90831
90585
90419
90288
90200
90120
90068
89960

result:

wrong answer 31st numbers differ - expected: '90035', found: '89960'