結果

問題 No.225 文字列変更(medium)
ユーザー simansiman
提出日時 2016-03-31 00:10:34
言語 Ruby
(3.3.0)
結果
AC  
実行時間 694 ms / 5,000 ms
コード長 543 bytes
コンパイル時間 384 ms
コンパイル使用メモリ 11,320 KB
実行使用メモリ 22,768 KB
最終ジャッジ日時 2023-08-27 06:15:35
合計ジャッジ時間 9,913 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 326 ms
18,148 KB
testcase_01 AC 498 ms
20,352 KB
testcase_02 AC 83 ms
15,156 KB
testcase_03 AC 83 ms
15,120 KB
testcase_04 AC 81 ms
15,240 KB
testcase_05 AC 83 ms
15,100 KB
testcase_06 AC 83 ms
15,100 KB
testcase_07 AC 82 ms
15,208 KB
testcase_08 AC 83 ms
15,056 KB
testcase_09 AC 83 ms
15,148 KB
testcase_10 AC 83 ms
15,124 KB
testcase_11 AC 84 ms
15,156 KB
testcase_12 AC 656 ms
22,232 KB
testcase_13 AC 694 ms
22,768 KB
testcase_14 AC 681 ms
22,616 KB
testcase_15 AC 680 ms
22,232 KB
testcase_16 AC 660 ms
22,336 KB
testcase_17 AC 664 ms
22,268 KB
testcase_18 AC 645 ms
22,112 KB
testcase_19 AC 657 ms
22,252 KB
testcase_20 AC 641 ms
21,872 KB
testcase_21 AC 657 ms
22,248 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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
0