#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();
int dp[N+1][M+1],l[N+1][M+1];
for(int i=0;i<=N;i++){
l[i][0]=dp[i][0]=i+3;
}
for(int i=0;i<=M;i++){
l[0][i]=dp[0][i]=i+3;
}
dp[0][0]=0;
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);
if(A[i-1]==B[j-1]){
dp[i][j]=min(dp[i][j],dp[i-1][j-1]+1);
}
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 | 1828 KiB | ||||
2 | Accepted | 3ms | 2172 KiB | ||||
subtask2 | 9/9 | ||||||
3 | Accepted | 34ms | 50220 KiB | ||||
4 | Accepted | 82ms | 60400 KiB | ||||
5 | Accepted | 85ms | 70712 KiB | ||||
6 | Accepted | 76ms | 48892 KiB | ||||
7 | Accepted | 104ms | 70828 KiB | ||||
8 | Accepted | 93ms | 68156 KiB | ||||
subtask3 | 11/11 | ||||||
9 | Accepted | 3ms | 2736 KiB | ||||
10 | Accepted | 3ms | 2872 KiB | ||||
11 | Accepted | 3ms | 2948 KiB | ||||
12 | Accepted | 3ms | 3084 KiB | ||||
13 | Accepted | 3ms | 3300 KiB | ||||
14 | Accepted | 3ms | 3524 KiB | ||||
subtask4 | 13/13 | ||||||
15 | Accepted | 3ms | 3532 KiB | ||||
16 | Accepted | 3ms | 3604 KiB | ||||
17 | Accepted | 3ms | 3552 KiB | ||||
18 | Accepted | 3ms | 3532 KiB | ||||
19 | Accepted | 3ms | 3548 KiB | ||||
20 | Accepted | 3ms | 3516 KiB | ||||
subtask5 | 24/24 | ||||||
21 | Accepted | 3ms | 3988 KiB | ||||
22 | Accepted | 3ms | 4384 KiB | ||||
23 | Accepted | 3ms | 4144 KiB | ||||
24 | Accepted | 3ms | 4052 KiB | ||||
25 | Accepted | 3ms | 3736 KiB | ||||
26 | Accepted | 4ms | 4176 KiB | ||||
subtask6 | 43/43 | ||||||
27 | Accepted | 37ms | 57160 KiB | ||||
28 | Accepted | 87ms | 63692 KiB | ||||
29 | Accepted | 94ms | 79020 KiB | ||||
30 | Accepted | 108ms | 81760 KiB | ||||
31 | Accepted | 54ms | 37204 KiB | ||||
32 | Accepted | 81ms | 60260 KiB | ||||
33 | Accepted | 104ms | 68896 KiB | ||||
34 | Accepted | 101ms | 80872 KiB |