QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#389915 | #5312. Levenshtein Distance | NATURAL6 | WA | 800ms | 21304kb | C++14 | 2.4kb | 2024-04-14 21:07:46 | 2024-04-14 21:07:46 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
inline int qread()
{
int a=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)){(a*=10)+=(ch^48);ch=getchar();}
return a*f;
}
int K,n,m,len,ans[100],dp[100][100],mn[100];
char S[100010],T[100010];
int sa[200010],rk[200010],a[200010],val[200010],tp,h[200010],st[18][200010];
inline void ssort()
{
memset(val,0,(tp+1)<<2);
for(int i=1;i<=len;++i)++val[rk[i]];
for(int i=1;i<=tp;++i)val[i]+=val[i-1];
for(int i=len;i;--i)sa[val[rk[a[i]]]--]=a[i];
return ;
}
inline int LCP(int x,int y)
{
if(x>n||y>m)return 0;
int px=rk[x],py=rk[n+y];
if(px>py)swap(px,py);
int s=31-__builtin_clz(py-px++);
return min({st[s][px],st[s][py-(1<<s)+1],n-x+1});
}
signed main()
{
K=qread();
scanf("%s%s",S+1,T+1);
len=n=strlen(S+1),m=strlen(T+1);
for(int i=1;i<=m;++i)S[++len]=T[i];
for(int i=1;i<=len;++i)rk[i]=S[i],a[i]=i;
tp=max(n,128);ssort();
for(int i=1,p=0;i<len;i<<=1,tp=p)
{
p=0;for(int j=i;j;--j)a[++p]=len-i+j;
for(int j=1;j<=len;++j)if(sa[j]>i)a[++p]=sa[j]-i;
ssort();memcpy(a,rk,(len+1)<<2);p=0;
for(int j=1;j<=len;++j)rk[sa[j]]=(a[sa[j]]^a[sa[j-1]]||a[sa[j]+i]^a[sa[j-1]+i])?++p:p;
}
for(int i=1;i<=len;++i)rk[sa[i]]=i;
for(int i=1,j,k=0;i<=len;++i)
{
if(rk[i]==1)continue;
if(k)--k;j=sa[rk[i]-1];
while(i+k<=len&&j+k<=len&&S[i+k]==S[j+k])++k;
h[rk[i]]=k;st[0][rk[i]]=k;
}
for(int i=1;i<=17;++i)for(int j=1;j+(1<<i)-1<=len;++j)st[i][j]=min(st[i-1][j],st[i-1][j+(1<<(i-1))]);
for(int l=1;l<=m&&l+n-K+1<=m;++l)
{
for(int i=0;i<=K;++i)memset(dp[i],-63,(K<<1|1)<<3);
memset(mn,-1,(K<<1|1)<<2);dp[0][K]=LCP(1,l);
for(int i=0,A,B;i<=K;++i)for(int j=-i;j<=i;++j)if(dp[i][j+K]>=0)
{
A=dp[i][j+K];B=l+A+j-1;
if(A==n&&!~mn[j+K])mn[j+K]=i;
if(i==K)continue;
dp[i+1][j+K]=max(dp[i+1][j+K],A<n&&B<m?A+LCP(A+2,B+2)+1:A);
dp[i+1][j+K-1]=max(dp[i+1][j+K-1],A<n?A+LCP(A+2,B+1)+1:(A+j>0?A:-1000000000));
dp[i+1][j+K+1]=max(dp[i+1][j+K+1],B<m?A+LCP(A+1,B+2):(A>0?A-1:-1000000000));
}
for(int i=max(-K,1-n);i<=K;++i)if(~mn[i+K])++ans[mn[i+K]];
}
for(int i=0;i<=K;++i)printf("%d\n",ans[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 10080kb
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: 153ms
memory: 21172kb
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: 0
Accepted
time: 370ms
memory: 21152kb
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 90035
result:
ok 31 numbers
Test #4:
score: 0
Accepted
time: 800ms
memory: 21296kb
input:
30 AAABBAAAAAAAAAAAAABAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAABAAAAABAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABABAAAABAAAABAAAABAAAAABAAAAAABAAAAAAAAABAAABAAABBAAAAAAAAAAAAAAAABAABAAABAAAAAAAAAAAAABAAAAAAAAAAAAAAAABAAABBAAAAAAAAAAAAAAAAAAAAAAAAAABAABAABABAAAAAAAAAAAAAAA...
output:
0 0 0 0 1 28 263 1410 6434 22523 56017 115080 189633 263874 316906 339254 332825 312943 286470 263283 246310 235032 227182 221294 216978 213734 211178 208848 206945 205393 204279
result:
ok 31 numbers
Test #5:
score: 0
Accepted
time: 394ms
memory: 21272kb
input:
30 ABABAABAAABAAAA AABBABABBBBBAAABABAABBAAABBBAABABBBABABABABABBABBBAAAAABBAAABBABABABABABBAAABBAAABAAABBBBBBBAABABBBAAAAABAABBBABBABBBABBBABABAABABBBAAABBABBAAABBBBBBBAABAABABAAAAAABBAABAAABBBAABBAABBAABBABABAAAAAAAABBBBBAAABABABBABAAAAABAABAABAABAABAAABABBABBBABAAABBBABABAABAABBBAABABBAABBAAAABAB...
output:
2 125 1938 15793 70756 178090 282937 325020 310617 277899 244094 217672 206966 202456 198644 105535 102767 100355 98411 96655 95310 94124 93217 92487 91872 91414 91039 90741 90555 90397 90276
result:
ok 31 numbers
Test #6:
score: 0
Accepted
time: 664ms
memory: 21304kb
input:
30 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...
output:
0 0 0 0 1 91 1082 14598 58877 123681 212928 258264 253856 277926 265254 243456 217809 198008 190004 184665 184470 183593 183524 183406 183335 183255 183185 183142 183078 182991 182922
result:
ok 31 numbers
Test #7:
score: -100
Wrong Answer
time: 437ms
memory: 21100kb
input:
30 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAABABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...
output:
1 460 44032 126686 201431 222795 213509 199190 187254 184699 184159 183907 183818 183558 183500 183466 183412 183393 183343 183299 183275 183236 183163 183127 183105 183056 183010 182971 182910 182719 182436
result:
wrong answer 31st numbers differ - expected: '182437', found: '182436'