結果

問題 No.225 文字列変更(medium)
ユーザー periberryperiberry
提出日時 2018-05-31 17:44:02
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 444 bytes
コンパイル時間 102 ms
コンパイル使用メモリ 11,228 KB
実行使用メモリ 23,452 KB
最終ジャッジ日時 2023-09-12 21:00:16
合計ジャッジ時間 9,451 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 AC 92 ms
23,064 KB
testcase_03 AC 92 ms
23,052 KB
testcase_04 AC 94 ms
23,192 KB
testcase_05 AC 92 ms
22,952 KB
testcase_06 AC 93 ms
23,208 KB
testcase_07 AC 91 ms
23,148 KB
testcase_08 AC 92 ms
23,248 KB
testcase_09 AC 92 ms
22,992 KB
testcase_10 AC 93 ms
23,068 KB
testcase_11 AC 92 ms
23,264 KB
testcase_12 AC 646 ms
23,208 KB
testcase_13 AC 692 ms
23,152 KB
testcase_14 AC 683 ms
23,032 KB
testcase_15 AC 664 ms
23,264 KB
testcase_16 AC 662 ms
23,208 KB
testcase_17 AC 662 ms
23,276 KB
testcase_18 AC 639 ms
23,068 KB
testcase_19 AC 655 ms
23,296 KB
testcase_20 AC 629 ms
22,992 KB
testcase_21 AC 654 ms
23,020 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def diff
  n, m = gets.chomp.split(" ").map(&:to_i)
  s = gets.chomp
  t = gets.chomp
  inf = 100000007
  dp = Array.new(1000){Array.new(1000, 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][j+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