53082023-04-25 18:59:15gortomiRegexcpp17Wrong answer 0/100196ms82696 KiB
#include <bits/stdc++.h>
using namespace std;
void solve()
{
    string a, b;
    cin >> a >> b;
    int n = a.size(), m = b.size();
    vector<vector<int> > dp1(n + 1, vector<int>(m + 1)), dp2(n + 1, vector<int>(m + 1));
    for(int i = 0; i <= n; i++)
    {
        dp1[i][m] = n - i + 3;
        dp2[i][m] = n - i;
    }
    for(int i = 0; i <= m; i++)
    {
        dp1[n][i] = m - i + 3;
        dp2[n][i] = m - i;
    }
    dp1[n][m] = 0;
    for(int i = n - 1; i >= 0; i--)
    {
        for(int j = m - 1; j >= 0; j--)
        {
            if(a[i] == b[j])
            {
                dp1[i][j] = dp1[i + 1][j + 1] + 1;
                dp2[i][j] = dp1[i + 1][j + 1] + 1;
            }
            else dp1[i][j] = min(dp2[i + 1][j] + 4, dp2[i][j + 1] + 4);
            dp2[i][j] = min(dp2[i][j], dp2[i + 1][j] + 1);
            dp2[i][j] = min(dp2[i][j], dp2[i][j + 1] + 1);
        }
    }
    cout << dp1[0][0] << "\n";
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--) solve();
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1836 KiB
2Wrong answer3ms2184 KiB
subtask20/9
3Wrong answer30ms49968 KiB
4Wrong answer123ms60624 KiB
5Wrong answer142ms70844 KiB
6Wrong answer146ms49136 KiB
7Wrong answer165ms71408 KiB
8Wrong answer142ms68384 KiB
subtask30/11
9Wrong answer3ms3080 KiB
10Wrong answer3ms3188 KiB
11Wrong answer3ms3196 KiB
12Wrong answer3ms3396 KiB
13Wrong answer3ms3608 KiB
14Wrong answer3ms3816 KiB
subtask40/13
15Wrong answer3ms3952 KiB
16Wrong answer3ms3968 KiB
17Wrong answer3ms4008 KiB
18Wrong answer3ms3992 KiB
19Wrong answer3ms4188 KiB
20Wrong answer3ms4180 KiB
subtask50/24
21Wrong answer3ms4952 KiB
22Wrong answer4ms5096 KiB
23Wrong answer4ms5196 KiB
24Wrong answer4ms5116 KiB
25Wrong answer3ms5028 KiB
26Wrong answer4ms5216 KiB
subtask60/43
27Wrong answer39ms58368 KiB
28Wrong answer156ms64708 KiB
29Wrong answer158ms79964 KiB
30Wrong answer194ms82696 KiB
31Wrong answer86ms38140 KiB
32Wrong answer143ms61408 KiB
33Wrong answer196ms70240 KiB
34Wrong answer177ms82104 KiB