#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
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],a[N+1][M+1],b[N+1][M+1];
memset(dp,0,sizeof(dp));
memset(l,0,sizeof(l));
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
for(int i=1;i<=N;i++){
for(int j=1;j<=M;j++){
l[i][j]=i+j-1-min(i==1?j:dp[i-1][j],j==1?i:dp[i][j-1]);
l[i][j]=max(l[i][j],max(l[i-1][j],l[i][j-1]));
a[i][j]=i+j-1-(i==1?j:dp[i-1][j]);
b[i][j]=i+j-1-(j==1?i:dp[i][j-1]);
dp[i][j]=i+j+3-l[i][j];
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);
}
// 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 | Wrong answer | 3ms | 2272 KiB | ||||
subtask2 | 0/9 | ||||||
3 | Wrong answer | 101ms | 193944 KiB | ||||
4 | Wrong answer | 252ms | 234900 KiB | ||||
5 | Wrong answer | 268ms | 274932 KiB | ||||
6 | Wrong answer | 238ms | 188548 KiB | ||||
7 | Wrong answer | 437ms | 276160 KiB | ||||
8 | Wrong answer | 377ms | 264344 KiB | ||||
subtask3 | 0/11 | ||||||
9 | Accepted | 3ms | 3072 KiB | ||||
10 | Wrong answer | 3ms | 3436 KiB | ||||
11 | Wrong answer | 3ms | 3528 KiB | ||||
12 | Wrong answer | 3ms | 3516 KiB | ||||
13 | Wrong answer | 3ms | 3716 KiB | ||||
14 | Wrong answer | 3ms | 3932 KiB | ||||
subtask4 | 0/13 | ||||||
15 | Wrong answer | 3ms | 4244 KiB | ||||
16 | Wrong answer | 3ms | 4420 KiB | ||||
17 | Wrong answer | 3ms | 4524 KiB | ||||
18 | Wrong answer | 3ms | 4256 KiB | ||||
19 | Wrong answer | 3ms | 4216 KiB | ||||
20 | Wrong answer | 3ms | 4476 KiB | ||||
subtask5 | 0/24 | ||||||
21 | Wrong answer | 4ms | 7168 KiB | ||||
22 | Wrong answer | 6ms | 8176 KiB | ||||
23 | Wrong answer | 4ms | 7316 KiB | ||||
24 | Wrong answer | 4ms | 6936 KiB | ||||
25 | Wrong answer | 4ms | 6408 KiB | ||||
26 | Wrong answer | 4ms | 7812 KiB | ||||
subtask6 | 0/43 | ||||||
27 | Wrong answer | 112ms | 218884 KiB | ||||
28 | Wrong answer | 270ms | 244988 KiB | ||||
29 | Wrong answer | 294ms | 306144 KiB | ||||
30 | Wrong answer | 335ms | 316880 KiB | ||||
31 | Wrong answer | 166ms | 139200 KiB | ||||
32 | Wrong answer | 324ms | 231780 KiB | ||||
33 | Wrong answer | 419ms | 266556 KiB | ||||
34 | Wrong answer | 317ms | 314260 KiB |