結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 486 ms
20,168 KB
testcase_02 WA -
testcase_03 AC 79 ms
15,188 KB
testcase_04 AC 79 ms
15,260 KB
testcase_05 AC 80 ms
15,004 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 82 ms
15,152 KB
testcase_10 AC 82 ms
15,084 KB
testcase_11 WA -
testcase_12 AC 644 ms
22,252 KB
testcase_13 AC 691 ms
22,756 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 657 ms
22,436 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 651 ms
22,208 KB
testcase_20 WA -
testcase_21 AC 651 ms
22,224 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(n+1){Array.new(m+1, inf)}
  dp[0][0] = 0

  n.times do |i|
    m.times 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