101732024-03-28 23:59:41111Regexcpp17Wrong answer 0/100437ms316880 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],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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1824 KiB
2Wrong answer3ms2272 KiB
subtask20/9
3Wrong answer101ms193944 KiB
4Wrong answer252ms234900 KiB
5Wrong answer268ms274932 KiB
6Wrong answer238ms188548 KiB
7Wrong answer437ms276160 KiB
8Wrong answer377ms264344 KiB
subtask30/11
9Accepted3ms3072 KiB
10Wrong answer3ms3436 KiB
11Wrong answer3ms3528 KiB
12Wrong answer3ms3516 KiB
13Wrong answer3ms3716 KiB
14Wrong answer3ms3932 KiB
subtask40/13
15Wrong answer3ms4244 KiB
16Wrong answer3ms4420 KiB
17Wrong answer3ms4524 KiB
18Wrong answer3ms4256 KiB
19Wrong answer3ms4216 KiB
20Wrong answer3ms4476 KiB
subtask50/24
21Wrong answer4ms7168 KiB
22Wrong answer6ms8176 KiB
23Wrong answer4ms7316 KiB
24Wrong answer4ms6936 KiB
25Wrong answer4ms6408 KiB
26Wrong answer4ms7812 KiB
subtask60/43
27Wrong answer112ms218884 KiB
28Wrong answer270ms244988 KiB
29Wrong answer294ms306144 KiB
30Wrong answer335ms316880 KiB
31Wrong answer166ms139200 KiB
32Wrong answer324ms231780 KiB
33Wrong answer419ms266556 KiB
34Wrong answer317ms314260 KiB