40492023-03-10 23:37:22zsomborRegexcpp17Wrong answer 24/100280ms216560 KiB
#include <iostream>
#include <vector>
using namespace std;

string a, b;
int n, m, I, J, ans;
vector <vector<int>> dp(3e3, vector<int>(3e3, 1e9));
vector <vector<int>> mni(3e3, vector<int>(3e3, 0));
vector <vector<int>> mnj(3e3, vector<int>(3e3, 0));

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

int main()
{
    int t;
    cin >> t;
    for (int i = 0; i < t; i++) solve();
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted71ms213624 KiB
2Accepted92ms213940 KiB
subtask20/9
3Wrong answer104ms214156 KiB
4Wrong answer207ms214372 KiB
5Wrong answer231ms214584 KiB
6Wrong answer229ms214792 KiB
7Wrong answer275ms214752 KiB
8Wrong answer248ms214748 KiB
subtask311/11
9Accepted90ms214740 KiB
10Accepted90ms214744 KiB
11Accepted72ms214816 KiB
12Accepted90ms214740 KiB
13Accepted90ms215000 KiB
14Accepted72ms215324 KiB
subtask413/13
15Accepted90ms215644 KiB
16Accepted92ms215376 KiB
17Accepted92ms215380 KiB
18Accepted92ms215452 KiB
19Accepted72ms215520 KiB
20Accepted90ms215848 KiB
subtask50/24
21Accepted92ms216056 KiB
22Wrong answer75ms216248 KiB
23Accepted92ms216244 KiB
24Wrong answer75ms216460 KiB
25Wrong answer92ms216348 KiB
26Wrong answer75ms216224 KiB
subtask60/43
27Accepted107ms216376 KiB
28Wrong answer221ms216232 KiB
29Wrong answer225ms216232 KiB
30Wrong answer277ms216304 KiB
31Wrong answer187ms216348 KiB
32Wrong answer231ms216300 KiB
33Wrong answer280ms216560 KiB
34Wrong answer261ms216512 KiB