53532023-04-26 11:04:33sztomiRegexcpp11Runtime error 57/1001.455s1045956 KiB
#include <bits/stdc++.h>

using namespace std;

const int INF = 1e5;

string a, b;

vector<vector<vector<int>>> dp;

int megold(int a_ind, int b_ind, bool nyitott){
    if(a_ind == a.size()){
        if(b_ind == b.size()){
            return 0;
        }
        else{
            return (b.size() - b_ind) + 3*(!nyitott);
        }
    }
    if(b_ind == b.size()){
        return (a.size() - a_ind) + 3*(!nyitott);
    }

    if(dp[a_ind][b_ind][nyitott] != -1){
        return dp[a_ind][b_ind][nyitott];
    }

    int ret = INF;
    if(nyitott){
        ret = min(ret, megold(a_ind+1, b_ind, true) + 1);
        ret = min(ret, megold(a_ind, b_ind+1, true) + 1);

        if(a[a_ind] == b[b_ind]){
            ret = min(ret, megold(a_ind+1, b_ind+1, false) + 1);
        }
    }
    else{
        ret = min(ret, megold(a_ind+1, b_ind, true) + 4);
        ret = min(ret, megold(a_ind, b_ind+1, true) + 4);

        if(a[a_ind] == b[b_ind]){
            ret = min(ret, megold(a_ind+1, b_ind+1, false) + 1);
        }
    }

    dp[a_ind][b_ind][nyitott] = ret;
    return ret;
}


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    // dp proba?
    int t;
    cin >> t;
    while(t--){
        cin >> a >> b;
        dp.assign(a.size(), vector<vector<int>>(b.size(), vector<int>(2, -1)));
        cout << megold(0, 0, false) << "\n";
    }

/*
    for(int k = 0; k < 2; k++){
        cout << "\t";
        for(int i = 0; i < b.size(); i++){
            cout << i << "\t";
        }
        cout << "\n";
        for(int i = 0; i < a.size(); i++){
            cout << i << "\t";
            for(int j = 0; j < b.size(); j++){
                cout << dp[i][j][k] << "\t";
            }
            cout << "\n";
        }
        cout << "----------------------\n";
    }
*/
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted3ms2532 KiB
subtask29/9
3Accepted354ms338280 KiB
4Accepted1.08s689452 KiB
5Accepted904ms479556 KiB
6Accepted986ms640836 KiB
7Accepted1.36s739004 KiB
8Accepted1.243s815312 KiB
subtask311/11
9Accepted3ms2916 KiB
10Accepted3ms3016 KiB
11Accepted3ms3140 KiB
12Accepted2ms3248 KiB
13Accepted3ms3428 KiB
14Accepted2ms3516 KiB
subtask413/13
15Accepted3ms4080 KiB
16Accepted4ms4636 KiB
17Accepted4ms4860 KiB
18Accepted4ms4424 KiB
19Accepted3ms4040 KiB
20Accepted4ms4600 KiB
subtask524/24
21Accepted8ms8760 KiB
22Accepted14ms10916 KiB
23Accepted14ms10832 KiB
24Accepted14ms11632 KiB
25Accepted12ms9296 KiB
26Accepted19ms14028 KiB
subtask60/43
27Accepted437ms379580 KiB
28Accepted1.304s669040 KiB
29Accepted1.376s932284 KiB
30Runtime error832ms1045956 KiB
31Accepted778ms467868 KiB
32Accepted987ms515452 KiB
33Accepted1.11s462684 KiB
34Accepted1.455s888188 KiB