// Source: https://usaco.guide/general/io
#include <bits/stdc++.h>
using namespace std;
const int lim = 2000000000;
int main() {
int t;cin >> t;
while(t--){
string a , b; cin >> a >> b;
int n = a.size() , m = b.size();
vector<vector<int>> dp1(n+2 , vector<int>(m+2 , lim)) , dp2(n+2 , vector<int>(m+2 , lim));
dp1[1][1] = 0;
dp2[1][1] = 3;
for(int i = 1; i < n+2; i++){
for(int j = 1; j < m+2; j++){
dp2[i][j] = min(min(min(dp1[i-1][j]+4 , dp1[i][j-1]+4) , min(dp2[i-1][j]+1 , dp2[i][j-1]+1)), dp2[i][j]);
if(i != 1 && j!=1 && a[i-2] == b[i-2]){
dp1[i][j] = min(dp1[i-1][j-1]+1 , dp1[i][j]);
}else{
dp1[i][j] = min(dp2[i][j] , dp1[i][j]);
}
}
}
cout << dp1.back().back() << "\n";
}
}
| Subtask | Sum | Test | Verdict | Time | Memory | ||
|---|---|---|---|---|---|---|---|
| subtask1 | 0/0 | ||||||
| 1 | Accepted | 1ms | 316 KiB | ||||
| 2 | Wrong answer | 1ms | 316 KiB | ||||
| subtask2 | 0/9 | ||||||
| 3 | Wrong answer | 39ms | 24372 KiB | ||||
| 4 | Wrong answer | 170ms | 29676 KiB | ||||
| 5 | Wrong answer | 152ms | 34612 KiB | ||||
| 6 | Wrong answer | 152ms | 23588 KiB | ||||
| 7 | Wrong answer | 226ms | 34664 KiB | ||||
| 8 | Wrong answer | 170ms | 33236 KiB | ||||
| subtask3 | 0/11 | ||||||
| 9 | Accepted | 1ms | 508 KiB | ||||
| 10 | Wrong answer | 1ms | 508 KiB | ||||
| 11 | Wrong answer | 1ms | 316 KiB | ||||
| 12 | Accepted | 1ms | 564 KiB | ||||
| 13 | Wrong answer | 1ms | 316 KiB | ||||
| 14 | Wrong answer | 1ms | 316 KiB | ||||
| subtask4 | 0/13 | ||||||
| 15 | Wrong answer | 1ms | 316 KiB | ||||
| 16 | Wrong answer | 1ms | 316 KiB | ||||
| 17 | Wrong answer | 1ms | 316 KiB | ||||
| 18 | Wrong answer | 1ms | 316 KiB | ||||
| 19 | Wrong answer | 1ms | 316 KiB | ||||
| 20 | Wrong answer | 1ms | 316 KiB | ||||
| subtask5 | 0/24 | ||||||
| 21 | Wrong answer | 2ms | 564 KiB | ||||
| 22 | Wrong answer | 2ms | 820 KiB | ||||
| 23 | Wrong answer | 2ms | 756 KiB | ||||
| 24 | Wrong answer | 2ms | 564 KiB | ||||
| 25 | Wrong answer | 2ms | 648 KiB | ||||
| 26 | Wrong answer | 2ms | 684 KiB | ||||
| subtask6 | 0/43 | ||||||
| 27 | Wrong answer | 43ms | 27188 KiB | ||||
| 28 | Wrong answer | 156ms | 30596 KiB | ||||
| 29 | Wrong answer | 162ms | 38316 KiB | ||||
| 30 | Wrong answer | 216ms | 39552 KiB | ||||
| 31 | Wrong answer | 111ms | 17204 KiB | ||||
| 32 | Wrong answer | 125ms | 28724 KiB | ||||
| 33 | Wrong answer | 193ms | 33076 KiB | ||||
| 34 | Wrong answer | 193ms | 39220 KiB | ||||