結果

問題 No.225 文字列変更(medium)
ユーザー pome-botpome-bot
提出日時 2020-09-02 11:39:28
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 639 bytes
コンパイル時間 330 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 19,584 KB
最終ジャッジ日時 2024-05-01 10:28:56
合計ジャッジ時間 8,378 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

# https://qiita.com/drken/items/a5e6fe22863b7992efdb
# https://yukicoder.me/problems/no/225

# n m
# s
# t

n, m = gets.split.map(&:to_i)
s = gets.chomp
t = gets.chomp

# inf = [n, m].max + 1
inf = 9999
array_dp = Array.new(n+1) { Array.new(m+1, inf) }
array_dp[0][0] = 0
n.times do |i|
  array_dp[i+1][0] = i+1
end
m.times do |i|
  array_dp[0][i+1] = i+1
end

n.times do |i|
  m.times do |j|
    if s[i] == t[j]
      array_dp[i+1][j+1] = [ array_dp[i][j], array_dp[i+1][j], array_dp[i][j+1] ].min
    else
      array_dp[i+1][j+1] = [ array_dp[i][j], array_dp[i+1][j], array_dp[i][j+1] ].min + 1
    end
  end
end

  puts array_dp[n][m]
0