#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";
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1828 KiB | ||||
2 | Wrong answer | 3ms | 2372 KiB | ||||
subtask2 | 0/9 | ||||||
3 | Wrong answer | 379ms | 337600 KiB | ||||
4 | Wrong answer | 1.118s | 689240 KiB | ||||
5 | Wrong answer | 916ms | 479576 KiB | ||||
6 | Wrong answer | 1.014s | 640800 KiB | ||||
7 | Wrong answer | 1.299s | 738988 KiB | ||||
8 | Wrong answer | 1.286s | 815448 KiB | ||||
subtask3 | 0/11 | ||||||
9 | Accepted | 3ms | 3320 KiB | ||||
10 | Accepted | 3ms | 3308 KiB | ||||
11 | Wrong answer | 3ms | 3292 KiB | ||||
12 | Wrong answer | 3ms | 3300 KiB | ||||
13 | Wrong answer | 3ms | 3424 KiB | ||||
14 | Wrong answer | 3ms | 3656 KiB | ||||
subtask4 | 0/13 | ||||||
15 | Wrong answer | 3ms | 4536 KiB | ||||
16 | Wrong answer | 4ms | 5108 KiB | ||||
17 | Wrong answer | 4ms | 5468 KiB | ||||
18 | Wrong answer | 4ms | 5264 KiB | ||||
19 | Wrong answer | 3ms | 4632 KiB | ||||
20 | Wrong answer | 4ms | 5400 KiB | ||||
subtask5 | 0/24 | ||||||
21 | Wrong answer | 7ms | 9524 KiB | ||||
22 | Wrong answer | 10ms | 11796 KiB | ||||
23 | Wrong answer | 13ms | 11760 KiB | ||||
24 | Wrong answer | 14ms | 12416 KiB | ||||
25 | Wrong answer | 12ms | 9996 KiB | ||||
26 | Wrong answer | 17ms | 14396 KiB | ||||
subtask6 | 0/43 | ||||||
27 | Wrong answer | 391ms | 379924 KiB | ||||
28 | Wrong answer | 1.246s | 669124 KiB | ||||
29 | Wrong answer | 1.296s | 931828 KiB | ||||
30 | Runtime error | 824ms | 1045884 KiB | ||||
31 | Wrong answer | 745ms | 467940 KiB | ||||
32 | Wrong answer | 876ms | 515520 KiB | ||||
33 | Wrong answer | 1.103s | 462616 KiB | ||||
34 | Wrong answer | 1.368s | 888000 KiB |