結果

問題 No.225 文字列変更(medium)
ユーザー periberryperiberry
提出日時 2018-05-31 17:20:26
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 442 bytes
コンパイル時間 429 ms
コンパイル使用メモリ 11,512 KB
実行使用メモリ 22,764 KB
最終ジャッジ日時 2023-09-12 20:59:12
合計ジャッジ時間 10,451 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 RE -
testcase_02 AC 80 ms
15,120 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 RE -
testcase_06 WA -
testcase_07 WA -
testcase_08 RE -
testcase_09 RE -
testcase_10 WA -
testcase_11 RE -
testcase_12 WA -
testcase_13 WA -
testcase_14 RE -
testcase_15 WA -
testcase_16 RE -
testcase_17 WA -
testcase_18 WA -
testcase_19 RE -
testcase_20 WA -
testcase_21 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def diff
  n, m = gets.chomp.split(" ").map(&:to_i)
  s = gets.chomp
  t = gets.chomp
  inf = 100000007
  dp = Array.new(n+2){Array.new(m+2, inf)}
  dp[0][0] = 0

  0.upto n do |i|
    0.upto m do |j|
      dp[i+1][j+1] = s[i] == t[j] ? [dp[i+1][j+1], dp[i][j]].min : [dp[i+1][i+1], dp[i][j] + 1 ].min
      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

  dp[n][m]
end

puts diff
0