53452023-04-26 10:02:07sztomiRegexcpp11Wrong answer 0/1001.368s1045884 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;
        }
    }
    if(b_ind == b.size()){
        return (a.size() - a_ind) + 3;
    }

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

    int ret = INF;
    // lehet egyutt haladni
    if(a[a_ind] == b[b_ind]){
        // ha nincs nyitva akkor sztem nincs ertelme kinyitni egyet
        if(!nyitott){
            ret = min(ret, megold(a_ind+1, b_ind+1, false) + 1);
        }
        else{
            // nyitva tartjuk
            ret = min(ret, megold(a_ind+1, b_ind, true) + 1);
            ret = min(ret, megold(a_ind, b_ind+1, true) + 1);
            // bezarjuk
            ret = min(ret, megold(a_ind+1, b_ind+1, true) + 1);
        }
    }
    else{
        if(!nyitott){
            // nyitunk egy ujat
            ret = min(ret, megold(a_ind+1, b_ind, true) + 1 + 3);
            ret = min(ret, megold(a_ind, b_ind+1, true) + 1 + 3);
        }
        else{
            ret = min(ret, megold(a_ind+1, b_ind, true) + 1);
            ret = min(ret, megold(a_ind, b_ind+1, true) + 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, 0) << "\n";
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Wrong answer3ms2372 KiB
subtask20/9
3Wrong answer379ms337600 KiB
4Wrong answer1.118s689240 KiB
5Wrong answer916ms479576 KiB
6Wrong answer1.014s640800 KiB
7Wrong answer1.299s738988 KiB
8Wrong answer1.286s815448 KiB
subtask30/11
9Accepted3ms3320 KiB
10Accepted3ms3308 KiB
11Wrong answer3ms3292 KiB
12Wrong answer3ms3300 KiB
13Wrong answer3ms3424 KiB
14Wrong answer3ms3656 KiB
subtask40/13
15Wrong answer3ms4536 KiB
16Wrong answer4ms5108 KiB
17Wrong answer4ms5468 KiB
18Wrong answer4ms5264 KiB
19Wrong answer3ms4632 KiB
20Wrong answer4ms5400 KiB
subtask50/24
21Wrong answer7ms9524 KiB
22Wrong answer10ms11796 KiB
23Wrong answer13ms11760 KiB
24Wrong answer14ms12416 KiB
25Wrong answer12ms9996 KiB
26Wrong answer17ms14396 KiB
subtask60/43
27Wrong answer391ms379924 KiB
28Wrong answer1.246s669124 KiB
29Wrong answer1.296s931828 KiB
30Runtime error824ms1045884 KiB
31Wrong answer745ms467940 KiB
32Wrong answer876ms515520 KiB
33Wrong answer1.103s462616 KiB
34Wrong answer1.368s888000 KiB