class Yukicoder def initialize n, m = gets.chomp.split.map(&:to_i) s = gets.chomp t = gets.chomp dp = Array.new(n+2){ Array.new(m+2, [n,m].max)} dp[0][0] = 0 0.upto(n) do |i| 0.upto(m) do |j| if s[i] == t[j] dp[i+1][j+1] = [dp[i+1][j+1], dp[i][j]].min else dp[i+1][j+1] = [dp[i+1][j+1], dp[i][j]+1].min end dp[i+1][j] = [dp[i+1][j], dp[i][j]+1].min dp[i][j+1] = [dp[i][j+1], dp[i][j]+1].min end end p dp[n][m] end end Yukicoder.new