QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#724190 | #5312. Levenshtein Distance | The_Shadow_Dragon | RE | 0ms | 0kb | C++14 | 3.2kb | 2024-11-08 10:40:19 | 2024-11-08 10:40:20 |
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()
{
freopen("edit.in","r",stdin);
freopen("edit.out","w",stdout);
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;
}
fclose(stdin);
fclose(stdout);
return 0;
}
詳細信息
Test #1:
score: 0
Dangerous Syscalls
input:
4 aaa aabbaab