53752023-04-26 20:12:37rmlanRegexcpp14Wrong answer 24/10093ms82612 KiB
#include<bits/stdc++.h>
using namespace std;

int main(){
    int t;
    cin >> t;
    while(t--){
        string a,b;
        cin >> a >> b;
        if(a.length() < b.length()) swap(a,b);
        int dp[a.length()+1][b.length()+1][2];
        dp[0][0][0]=0;
        dp[0][0][1]=3;
        for(int i = 1; i <= a.length(); i++){dp[i][0][1]=i+3; dp[i][0][0]=1e5;}
        for(int i = 1; i <= b.length(); i++){dp[0][i][1]=i+3; dp[0][i][0]=1e5;}
        for(int i = 1; i <= a.length(); i++){
            for(int j = 1; j <= b.length(); j++){


                dp[i][j][1]=dp[i-1][j][1]+1;
                dp[i][j][1]=min(dp[i][j][1], dp[i][j-1][1]+1);
                if(a[i-1]==b[j-1]){
                    dp[i][j][0]=min(dp[i-1][j-1][0], dp[i-1][j-1][1])+1;
                }else{
                    dp[i][j][0]=1e5;

                    dp[i][j][1]=min(dp[i][j][1], dp[i-1][j][0]+4);
                    dp[i][j][1]=min(dp[i][j][1], dp[i][j-1][0]+4);

                }

            }
        }
        cout << min(dp[a.length()][b.length()][0], dp[a.length()][b.length()][1]) << endl;
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1812 KiB
2Accepted3ms2028 KiB
subtask20/9
3Accepted32ms50212 KiB
4Accepted74ms60520 KiB
5Wrong answer78ms70588 KiB
6Wrong answer64ms48872 KiB
7Accepted93ms70944 KiB
8Accepted83ms68276 KiB
subtask311/11
9Accepted3ms3080 KiB
10Accepted3ms3272 KiB
11Accepted2ms3396 KiB
12Accepted2ms3424 KiB
13Accepted3ms3424 KiB
14Accepted2ms3548 KiB
subtask413/13
15Accepted3ms3956 KiB
16Accepted3ms3796 KiB
17Accepted3ms3700 KiB
18Accepted3ms3804 KiB
19Accepted3ms3764 KiB
20Accepted3ms4076 KiB
subtask50/24
21Accepted3ms4608 KiB
22Accepted4ms5132 KiB
23Accepted3ms5012 KiB
24Wrong answer3ms4948 KiB
25Accepted3ms4608 KiB
26Accepted4ms5056 KiB
subtask60/43
27Accepted32ms57876 KiB
28Wrong answer74ms64728 KiB
29Wrong answer87ms79960 KiB
30Accepted93ms82612 KiB
31Wrong answer46ms38116 KiB
32Wrong answer68ms61188 KiB
33Accepted89ms69892 KiB
34Wrong answer86ms81868 KiB