101742024-03-29 00:02:47111Regexcpp17Wrong answer 0/100148ms160648 KiB
#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];
		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);
				}
				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
2Accepted3ms2244 KiB
subtask20/9
3Wrong answer57ms98172 KiB
4Accepted119ms118736 KiB
5Wrong answer130ms139004 KiB
6Accepted98ms95932 KiB
7Wrong answer148ms139892 KiB
8Wrong answer123ms133984 KiB
subtask30/11
9Accepted2ms3376 KiB
10Accepted3ms3508 KiB
11Accepted2ms3588 KiB
12Accepted3ms3812 KiB
13Wrong answer3ms4052 KiB
14Wrong answer3ms4124 KiB
subtask40/13
15Accepted3ms4292 KiB
16Accepted3ms4232 KiB
17Wrong answer3ms4520 KiB
18Accepted3ms4432 KiB
19Accepted3ms4408 KiB
20Accepted3ms4424 KiB
subtask50/24
21Accepted3ms5676 KiB
22Wrong answer4ms6348 KiB
23Wrong answer4ms5856 KiB
24Accepted4ms5692 KiB
25Wrong answer3ms5268 KiB
26Accepted4ms6000 KiB
subtask60/43
27Accepted52ms111600 KiB
28Accepted126ms124612 KiB
29Accepted126ms155540 KiB
30Accepted141ms160648 KiB
31Wrong answer71ms71688 KiB
32Accepted105ms117868 KiB
33Accepted135ms135336 KiB
34Wrong answer133ms159172 KiB