40512023-03-11 00:47:53zsomborRegexcpp17Wrong answer 24/100126ms146172 KiB
#include <iostream>
#include <vector>
using namespace std;

string a, b;
int n, m, Mn;
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;
    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] = Mn + 2;
            if (a[i - 1] == b[j - 1]) dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] - 1);
            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
1Accepted61ms142888 KiB
2Accepted50ms143368 KiB
subtask20/9
3Wrong answer71ms143496 KiB
4Wrong answer105ms143836 KiB
5Wrong answer105ms143920 KiB
6Wrong answer105ms144132 KiB
7Wrong answer104ms144388 KiB
8Wrong answer112ms144212 KiB
subtask311/11
9Accepted50ms144528 KiB
10Accepted48ms144616 KiB
11Accepted61ms144664 KiB
12Accepted50ms145032 KiB
13Accepted48ms144956 KiB
14Accepted61ms145084 KiB
subtask413/13
15Accepted50ms145296 KiB
16Accepted61ms145636 KiB
17Accepted61ms145588 KiB
18Accepted50ms145552 KiB
19Accepted48ms145896 KiB
20Accepted48ms145856 KiB
subtask50/24
21Accepted61ms145760 KiB
22Wrong answer63ms145672 KiB
23Accepted50ms145824 KiB
24Wrong answer61ms145776 KiB
25Wrong answer48ms145796 KiB
26Wrong answer61ms146048 KiB
subtask60/43
27Accepted74ms145900 KiB
28Wrong answer97ms146028 KiB
29Wrong answer97ms146104 KiB
30Wrong answer126ms146172 KiB
31Wrong answer79ms146168 KiB
32Wrong answer108ms146172 KiB
33Wrong answer126ms146172 KiB
34Wrong answer101ms146112 KiB