101772024-03-29 00:26:00111Regexcpp17Wrong answer 0/100134ms160584 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();
		// 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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1824 KiB
2Accepted3ms2208 KiB
subtask20/9
3Wrong answer54ms98084 KiB
4Accepted105ms118732 KiB
5Wrong answer112ms139004 KiB
6Accepted96ms95720 KiB
7Wrong answer131ms139548 KiB
8Wrong answer119ms133640 KiB
subtask30/11
9Accepted3ms3052 KiB
10Accepted3ms3304 KiB
11Accepted3ms3324 KiB
12Accepted3ms3324 KiB
13Wrong answer3ms3332 KiB
14Wrong answer3ms3424 KiB
subtask40/13
15Accepted3ms3636 KiB
16Accepted3ms3580 KiB
17Wrong answer3ms3860 KiB
18Accepted3ms4148 KiB
19Accepted3ms3964 KiB
20Accepted3ms4044 KiB
subtask50/24
21Accepted3ms5544 KiB
22Wrong answer4ms6228 KiB
23Wrong answer4ms5624 KiB
24Accepted4ms5580 KiB
25Wrong answer3ms5140 KiB
26Accepted4ms5880 KiB
subtask60/43
27Accepted59ms111472 KiB
28Accepted112ms124444 KiB
29Accepted126ms154976 KiB
30Accepted123ms160584 KiB
31Wrong answer61ms72032 KiB
32Accepted92ms117880 KiB
33Accepted130ms135280 KiB
34Wrong answer134ms159244 KiB