結果

問題 No.225 文字列変更(medium)
ユーザー simansiman
提出日時 2016-04-01 03:23:50
言語 Ruby
(3.3.0)
結果
AC  
実行時間 612 ms / 5,000 ms
コード長 578 bytes
コンパイル時間 43 ms
コンパイル使用メモリ 11,384 KB
実行使用メモリ 22,884 KB
最終ジャッジ日時 2023-08-27 06:15:44
合計ジャッジ時間 8,810 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 283 ms
18,272 KB
testcase_01 AC 441 ms
20,232 KB
testcase_02 AC 72 ms
15,164 KB
testcase_03 AC 75 ms
15,116 KB
testcase_04 AC 76 ms
15,280 KB
testcase_05 AC 77 ms
15,316 KB
testcase_06 AC 78 ms
15,052 KB
testcase_07 AC 76 ms
15,320 KB
testcase_08 AC 75 ms
15,088 KB
testcase_09 AC 76 ms
15,280 KB
testcase_10 AC 77 ms
15,136 KB
testcase_11 AC 76 ms
15,240 KB
testcase_12 AC 565 ms
22,288 KB
testcase_13 AC 612 ms
22,884 KB
testcase_14 AC 597 ms
22,556 KB
testcase_15 AC 582 ms
22,272 KB
testcase_16 AC 582 ms
22,324 KB
testcase_17 AC 586 ms
22,244 KB
testcase_18 AC 563 ms
22,028 KB
testcase_19 AC 573 ms
22,220 KB
testcase_20 AC 544 ms
21,968 KB
testcase_21 AC 574 ms
22,404 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+1){ Array.new(m+1, [n,m].max)}

    n.times do |y|
      dp[y][0] = y
    end

    m.times do |x|
      dp[0][x] = x
    end

    1.upto(n) do |i|
      1.upto(m) do |j|
        if s[i-1] == t[j-1]
          dp[i][j] = [dp[i][j], dp[i-1][j-1]].min
        else
          dp[i][j] = [dp[i][j], dp[i-1][j-1]+1].min
        end

        dp[i][j] = [dp[i][j], dp[i-1][j]+1, dp[i][j-1]+1].min
      end
    end

    p dp[n][m]
  end
end

Yukicoder.new
0