using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; int[] inputLength = Reader.GetInt(); this.Input1 = Reader.ReadLine(); this.Input2 = Reader.ReadLine(); int ans = this.GetAns(this.Input1, this.Input2); Console.WriteLine(ans); } private Dictionary> dic = new Dictionary>(); private int GetAns(string target, string goal) { if(!dic.ContainsKey(target)) { dic.Add(target, new Dictionary()); } if(dic[target].ContainsKey(goal)) { return dic[target][goal]; } int ans = int.MaxValue; if(target.Length == 0 && goal.Length > 0) { ans = goal.Length; } else if(target.Length > 0 && goal.Length == 0) { ans = target.Length; } else if(target.Length == 0 && goal.Length == 0) { ans = 0; } else { if(target[0] == goal[0]) { int idx = 1; for(int i=1; i= 2 && goal.IndexOf(target[0]) > 0) { int idx = goal.IndexOf(target[0]); ans = Math.Min(ans, this.GetAns(target, goal.Substring(idx)) + idx); } if(target.Length >= 2 && target.IndexOf(goal[0]) > 0) { int idx = target.IndexOf(goal[0]); ans = Math.Min(ans, this.GetAns(target.Substring(idx), goal) + idx); } if(target[0] != goal[0]) { ans = Math.Min(ans, this.GetAns(target.Substring(1), goal.Substring(1)) + 1); } } this.dic[target].Add(goal, ans); return ans; } private string Input1; private string Input2; public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 14 16 pirikapirirara poporinapeperuto "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } public static int[] GetInt(char delimiter = ' ', bool trim = false) { string inptStr = ReadLine(); if (trim) { inptStr = inptStr.Trim(); } string[] inpt = inptStr.Split(delimiter); int[] ret = new int[inpt.Length]; for (int i = 0; i < inpt.Length; i++) { ret[i] = int.Parse(inpt[i]); } return ret; } } static void Main() { Program prg = new Program(); prg.Proc(); } }