結果

問題 No.225 文字列変更(medium)
ユーザー Tsuneo YoshiokaTsuneo Yoshioka
提出日時 2015-06-12 22:47:49
言語 Ruby
(3.2.2)
結果
AC  
実行時間 695 ms / 5,000 ms
コード長 450 bytes
コンパイル時間 56 ms
コンパイル使用メモリ 11,552 KB
実行使用メモリ 22,748 KB
最終ジャッジ日時 2023-08-27 00:00:28
合計ジャッジ時間 9,732 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 320 ms
18,080 KB
testcase_01 AC 503 ms
20,264 KB
testcase_02 AC 81 ms
15,028 KB
testcase_03 AC 83 ms
15,280 KB
testcase_04 AC 82 ms
15,224 KB
testcase_05 AC 82 ms
15,200 KB
testcase_06 AC 83 ms
15,112 KB
testcase_07 AC 82 ms
15,172 KB
testcase_08 AC 80 ms
15,340 KB
testcase_09 AC 82 ms
15,224 KB
testcase_10 AC 81 ms
15,104 KB
testcase_11 AC 81 ms
15,268 KB
testcase_12 AC 651 ms
22,160 KB
testcase_13 AC 695 ms
22,748 KB
testcase_14 AC 675 ms
22,564 KB
testcase_15 AC 658 ms
22,220 KB
testcase_16 AC 668 ms
22,228 KB
testcase_17 AC 666 ms
22,380 KB
testcase_18 AC 642 ms
22,140 KB
testcase_19 AC 662 ms
22,312 KB
testcase_20 AC 632 ms
22,040 KB
testcase_21 AC 654 ms
22,356 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N,M=gets.split.map(&:to_i)
S=gets.chomp
T=gets.chomp
INF=10000
dp = Array.new(N+2).map{Array.new(M+2,INF)}
dp[0][0]=0

(0..N).each{|s|
    (0..M).each{|t|
        if(S[s]==T[t])
            dp[s+1][t+1] = [dp[s+1][t+1], dp[s][t]].min
        else
            dp[s+1][t+1] = [dp[s+1][t+1], dp[s][t]+1].min
        end
        dp[s+1][t] = [dp[s+1][t], dp[s][t]+1].min      
        dp[s][t+1] = [dp[s][t+1], dp[s][t]+1].min      
    }
}
puts dp[N][M]
0