#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T=-1;
cin>>T;
while(T--){
string A,B;
cin>>A>>B;
int N=A.size(),M=B.size();
// N=100,M=100;
// for(int i=0;i<N;i++)A+='a'+rand()%3;
// for(int i=0;i<M;i++)B+='a'+rand()%3;
int dp[N+1][M+1],l[N+1][M+1];
for(int i=0;i<=N;i++){
dp[i][0]=i;
l[i][0]=i+3;
}
for(int i=0;i<=M;i++){
dp[0][i]=i;
l[0][i]=i+3;
}
for(int i=1;i<=N;i++){
for(int j=1;j<=M;j++){
l[i][j]=dp[i][j]=min(l[i-1][j]+1,l[i][j-1]+1);
int k=0;
while(k<i&&k<j&&A[i-k-1]==B[j-k-1]){
k++;
dp[i][j]=min(dp[i][j],dp[i-k][j-k]+k);
break;
}
l[i][j]=min(l[i][j],dp[i][j]+3);
// cout<<setw(4)<<i<<' '<<j<<' '<<dp[i][j]<<' '<<l[i][j]<<'\n';
}
}
cout<<dp[N][M]<<'\n';
}
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1824 KiB | ||||
2 | Accepted | 3ms | 2208 KiB | ||||
subtask2 | 0/9 | ||||||
3 | Wrong answer | 54ms | 98084 KiB | ||||
4 | Accepted | 105ms | 118732 KiB | ||||
5 | Wrong answer | 112ms | 139004 KiB | ||||
6 | Accepted | 96ms | 95720 KiB | ||||
7 | Wrong answer | 131ms | 139548 KiB | ||||
8 | Wrong answer | 119ms | 133640 KiB | ||||
subtask3 | 0/11 | ||||||
9 | Accepted | 3ms | 3052 KiB | ||||
10 | Accepted | 3ms | 3304 KiB | ||||
11 | Accepted | 3ms | 3324 KiB | ||||
12 | Accepted | 3ms | 3324 KiB | ||||
13 | Wrong answer | 3ms | 3332 KiB | ||||
14 | Wrong answer | 3ms | 3424 KiB | ||||
subtask4 | 0/13 | ||||||
15 | Accepted | 3ms | 3636 KiB | ||||
16 | Accepted | 3ms | 3580 KiB | ||||
17 | Wrong answer | 3ms | 3860 KiB | ||||
18 | Accepted | 3ms | 4148 KiB | ||||
19 | Accepted | 3ms | 3964 KiB | ||||
20 | Accepted | 3ms | 4044 KiB | ||||
subtask5 | 0/24 | ||||||
21 | Accepted | 3ms | 5544 KiB | ||||
22 | Wrong answer | 4ms | 6228 KiB | ||||
23 | Wrong answer | 4ms | 5624 KiB | ||||
24 | Accepted | 4ms | 5580 KiB | ||||
25 | Wrong answer | 3ms | 5140 KiB | ||||
26 | Accepted | 4ms | 5880 KiB | ||||
subtask6 | 0/43 | ||||||
27 | Accepted | 59ms | 111472 KiB | ||||
28 | Accepted | 112ms | 124444 KiB | ||||
29 | Accepted | 126ms | 154976 KiB | ||||
30 | Accepted | 123ms | 160584 KiB | ||||
31 | Wrong answer | 61ms | 72032 KiB | ||||
32 | Accepted | 92ms | 117880 KiB | ||||
33 | Accepted | 130ms | 135280 KiB | ||||
34 | Wrong answer | 134ms | 159244 KiB |