Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.095 s | 13 KBi |
#2 |
Correcto
|
0.097 s | 13 KBi |
#3 |
Correcto
|
0.097 s | 13 KBi |
#4 |
Correcto
|
0.1 s | 13 KBi |
#5 |
Correcto
|
0.094 s | 13 KBi |
#6 |
Correcto
|
0.099 s | 13 KBi |
#7 |
Correcto
|
0.096 s | 13 KBi |
#8 |
Correcto
|
0.096 s | 13 KBi |
#9 |
Correcto
|
0.098 s | 13 KBi |
#10 |
Correcto
|
0.101 s | 13 KBi |
#11 |
Correcto
|
0.09 s | 13 KBi |
#12 |
Correcto
|
0.098 s | 13 KBi |
#13 |
Correcto
|
0.095 s | 13 KBi |
#14 |
Correcto
|
0.099 s | 13 KBi |
#15 |
Correcto
|
0.094 s | 13 KBi |
#16 |
Correcto
|
0.097 s | 13 KBi |
#17 |
Correcto
|
0.093 s | 13 KBi |
#18 |
Correcto
|
0.095 s | 13 KBi |
#19 |
Correcto
|
0.096 s | 13 KBi |
#20 |
Correcto
|
0.096 s | 13 KBi |
#21 |
Correcto
|
0.124 s | 17 KBi |
#22 |
Correcto
|
0.13 s | 17 KBi |
#23 |
Correcto
|
0.117 s | 17 KBi |
#24 |
Correcto
|
0.128 s | 17 KBi |
#25 |
Correcto
|
0.137 s | 18 KBi |
#26 |
Correcto
|
0.124 s | 17 KBi |
#27 |
Correcto
|
0.138 s | 17 KBi |
import java.util.Scanner; public class Main{ public static int distanciaLevenshtein(String s1, String s2) { int m = s1.length(); int n = s2.length(); // Crear una matriz de tamaño (m+1) x (n+1) e inicializarla int[][] dp = new int[m + 1][n + 1]; for (int i = 0; i <= m; i++) { dp[i][0] = i; } for (int j = 0; j <= n; j++) { dp[0][j] = j; } // Calcular la distancia de Levenshtein for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { if (s1.charAt(i - 1) != s2.charAt(j - 1)) { dp[i][j] = 1 + Math.min(Math.min(dp[i - 1][j], dp[i][j - 1]), dp[i - 1][j - 1]); } else { dp[i][j] = dp[i - 1][j - 1]; } } } return dp[m][n]; } public static void main(String[] args) { // Leer las strings de la entrada Scanner scanner = new Scanner(System.in); String s1 = scanner.nextLine(); String s2 = scanner.nextLine(); // Calcular la distancia de Levenshtein int distancia = distanciaLevenshtein(s1, s2); // Imprimir la distancia System.out.println(distancia); } }