40502023-03-11 00:30:48zsomborRegexcpp17Wrong answer 24/100107ms145512 KiB
#include <iostream>
#include <vector>
using namespace std;

string a, b;
int n, m, Mn, ans;
vector <vector <int>> dp(3e3, vector <int>(3e3, 1e9));
vector <vector <int>> mn(3e3, vector <int>(3e3, 0));

void solve() {
    cin >> a >> b;
    n = a.size();
    m = b.size();
    a = "a" + a;
    b = "a" + b;
    ans = dp[0][0] = n + m + 3;
    for (int i = 0; i <= n; i++) mn[i][0] = dp[0][0];
    for (int j = 0; j <= m; j++) mn[0][j] = dp[0][0];
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            Mn = min(mn[i - 1][j], mn[i][j - 1]);
            if (a[i] != b[j]) { mn[i][j] = Mn; continue; }
            dp[i][j] = (a[i - 1] == b[j - 1] ? dp[i - 1][j - 1] - 1 : Mn + 2);
            if (i == n && j == m) dp[i][j] -= 3;
            mn[i][j] = min(Mn, dp[i][j]);
        }
    }
    cout << mn[n][m] << endl;
}

int main()
{
    int t;
    cin >> t;
    for (int i = 0; i < t; i++) solve();
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted48ms142892 KiB
2Accepted61ms143232 KiB
subtask20/9
3Wrong answer71ms143572 KiB
4Wrong answer92ms143616 KiB
5Wrong answer90ms143828 KiB
6Wrong answer90ms144040 KiB
7Wrong answer104ms144116 KiB
8Wrong answer96ms144080 KiB
subtask311/11
9Accepted48ms144320 KiB
10Accepted61ms144072 KiB
11Accepted61ms144332 KiB
12Accepted61ms144548 KiB
13Accepted50ms144548 KiB
14Accepted48ms144672 KiB
subtask413/13
15Accepted61ms144744 KiB
16Accepted61ms144752 KiB
17Accepted61ms144748 KiB
18Accepted50ms144848 KiB
19Accepted48ms144928 KiB
20Accepted48ms145048 KiB
subtask50/24
21Accepted48ms145112 KiB
22Wrong answer48ms145108 KiB
23Accepted61ms145112 KiB
24Wrong answer50ms145120 KiB
25Wrong answer48ms145124 KiB
26Wrong answer48ms145120 KiB
subtask60/43
27Accepted72ms145456 KiB
28Wrong answer97ms145252 KiB
29Wrong answer97ms145272 KiB
30Wrong answer105ms145252 KiB
31Wrong answer79ms145244 KiB
32Wrong answer92ms145252 KiB
33Wrong answer107ms145512 KiB
34Wrong answer101ms145464 KiB