53742023-04-26 19:48:04rmlanRegexcpp14Wrong answer 24/100104ms83072 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++){
                if(a[i-1]==b[j-1]){
                    //cout << "ok";
                    dp[i][j][0]=min(dp[i-1][j-1][0], dp[i-1][j-1][1])+1;
                    dp[i][j][1]=dp[i-1][j-1][1]+2;
                    dp[i][j][1]=min(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);
                }else{

                    dp[i][j][0]=1e5;
                    dp[i][j][1]=dp[i-1][j-1][1]+2;
                    dp[i][j][1]=min(dp[i][j][1], dp[i-1][j-1][0]+5);
                    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);
                    dp[i][j][1]=min(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);
                }
            //cout << dp[i][j][0] << " "<<dp[i][j][1] << "    :" << i << " " << j << endl;
            }//cout << endl;
        }
        cout << min(dp[a.length()][b.length()][0], dp[a.length()][b.length()][1]) << endl;
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1816 KiB
2Accepted3ms2080 KiB
subtask20/9
3Accepted28ms50256 KiB
4Accepted78ms60592 KiB
5Wrong answer82ms70920 KiB
6Wrong answer70ms49376 KiB
7Accepted97ms71400 KiB
8Accepted87ms68468 KiB
subtask311/11
9Accepted3ms3204 KiB
10Accepted2ms3296 KiB
11Accepted3ms3280 KiB
12Accepted2ms3252 KiB
13Accepted3ms3384 KiB
14Accepted3ms3592 KiB
subtask413/13
15Accepted3ms3720 KiB
16Accepted3ms3984 KiB
17Accepted3ms4204 KiB
18Accepted3ms4520 KiB
19Accepted3ms4468 KiB
20Accepted3ms4372 KiB
subtask50/24
21Accepted3ms5132 KiB
22Accepted4ms5272 KiB
23Accepted3ms5152 KiB
24Wrong answer4ms5084 KiB
25Accepted3ms5064 KiB
26Accepted4ms5632 KiB
subtask60/43
27Accepted34ms58408 KiB
28Wrong answer82ms65012 KiB
29Wrong answer89ms80328 KiB
30Accepted101ms83072 KiB
31Wrong answer54ms38568 KiB
32Wrong answer82ms61620 KiB
33Accepted100ms70288 KiB
34Wrong answer104ms82224 KiB