101762024-03-29 00:18:07111Regexcpp17Time limit exceeded 0/1001.603s76284 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);
				}
				l[i][j]=min(l[i][j],dp[i][j]+3);
				// cout<<setw(4)<<i<<' '<<j<<' '<<dp[i][j]<<' '<<l[i][j]<<'\n';
				int x=1e9;
				for(int ii=0;ii<i;ii++){
					for(int jj=0;jj<j;jj++){
						x=min(x,l[ii][jj]+i+j-ii-jj);
					}
				}
				l[i][j]=min(l[i][j],x);
			}
		}
		cout<<dp[N][M]<<'\n';
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms2104 KiB
2Accepted14ms2500 KiB
subtask20/9
3Time limit exceeded1.603s49780 KiB
4Time limit exceeded1.564s41956 KiB
5Time limit exceeded1.539s70120 KiB
6Time limit exceeded1.569s46864 KiB
7Time limit exceeded1.56s69700 KiB
8Time limit exceeded1.555s53192 KiB
subtask30/11
9Accepted3ms3276 KiB
10Accepted3ms3496 KiB
11Accepted3ms3708 KiB
12Accepted3ms3776 KiB
13Wrong answer3ms3912 KiB
14Wrong answer3ms3924 KiB
subtask40/13
15Accepted14ms4268 KiB
16Accepted52ms4480 KiB
17Wrong answer54ms4764 KiB
18Accepted34ms4628 KiB
19Accepted20ms4608 KiB
20Accepted37ms4656 KiB
subtask50/24
21Accepted800ms6172 KiB
22Time limit exceeded1.575s5068 KiB
23Time limit exceeded1.56s4868 KiB
24Time limit exceeded1.58s4896 KiB
25Wrong answer989ms5828 KiB
26Time limit exceeded1.562s5020 KiB
subtask60/43
27Time limit exceeded1.583s58032 KiB
28Time limit exceeded1.564s48808 KiB
29Time limit exceeded1.572s61644 KiB
30Time limit exceeded1.56s76284 KiB
31Time limit exceeded1.575s37832 KiB
32Time limit exceeded1.6s20512 KiB
33Time limit exceeded1.58s69700 KiB
34Time limit exceeded1.569s68384 KiB