101792024-03-29 00:40:33111Regexcpp17Accepted 100/100108ms81760 KiB
#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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted3ms2172 KiB
subtask29/9
3Accepted34ms50220 KiB
4Accepted82ms60400 KiB
5Accepted85ms70712 KiB
6Accepted76ms48892 KiB
7Accepted104ms70828 KiB
8Accepted93ms68156 KiB
subtask311/11
9Accepted3ms2736 KiB
10Accepted3ms2872 KiB
11Accepted3ms2948 KiB
12Accepted3ms3084 KiB
13Accepted3ms3300 KiB
14Accepted3ms3524 KiB
subtask413/13
15Accepted3ms3532 KiB
16Accepted3ms3604 KiB
17Accepted3ms3552 KiB
18Accepted3ms3532 KiB
19Accepted3ms3548 KiB
20Accepted3ms3516 KiB
subtask524/24
21Accepted3ms3988 KiB
22Accepted3ms4384 KiB
23Accepted3ms4144 KiB
24Accepted3ms4052 KiB
25Accepted3ms3736 KiB
26Accepted4ms4176 KiB
subtask643/43
27Accepted37ms57160 KiB
28Accepted87ms63692 KiB
29Accepted94ms79020 KiB
30Accepted108ms81760 KiB
31Accepted54ms37204 KiB
32Accepted81ms60260 KiB
33Accepted104ms68896 KiB
34Accepted101ms80872 KiB