結果

問題 No.225 文字列変更(medium)
ユーザー maimai
提出日時 2017-06-29 13:46:49
言語 Ruby
(3.3.0)
結果
AC  
実行時間 542 ms / 5,000 ms
コード長 515 bytes
コンパイル時間 56 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 19,456 KB
最終ジャッジ日時 2024-04-15 04:50:08
合計ジャッジ時間 7,720 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 264 ms
14,848 KB
testcase_01 AC 386 ms
17,152 KB
testcase_02 AC 79 ms
12,288 KB
testcase_03 AC 80 ms
12,160 KB
testcase_04 AC 80 ms
12,288 KB
testcase_05 AC 81 ms
12,160 KB
testcase_06 AC 84 ms
12,160 KB
testcase_07 AC 81 ms
12,160 KB
testcase_08 AC 80 ms
12,288 KB
testcase_09 AC 81 ms
12,160 KB
testcase_10 AC 80 ms
12,288 KB
testcase_11 AC 80 ms
12,288 KB
testcase_12 AC 525 ms
19,072 KB
testcase_13 AC 542 ms
19,456 KB
testcase_14 AC 519 ms
19,328 KB
testcase_15 AC 507 ms
18,944 KB
testcase_16 AC 513 ms
19,200 KB
testcase_17 AC 517 ms
19,072 KB
testcase_18 AC 489 ms
18,816 KB
testcase_19 AC 515 ms
19,200 KB
testcase_20 AC 490 ms
18,816 KB
testcase_21 AC 520 ms
19,200 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def ascan; gets.split.map(&:to_i); end
def scan; gets.to_i; end

def editDistance(str1,str2)
    d = Array.new(str1.size+1){Array.new(str2.size+1)}
    0.upto(str1.size){|i| d[i][0] = i}
    0.upto(str2.size){|j| d[0][j] = j}
    1.upto(str1.size){|i|
        1.upto(str2.size){|j|
            d[i][j] = [d[i][j-1] + 1, d[i-1][j] + 1, d[i-1][j-1] + (str1[i-1] == str2[j-1] ? 0 : 1)].min
        }
    }
    # d.each{|l| puts l*" "}
    return d[str1.size][str2.size]
end

gets
p editDistance(gets.chomp, gets.chomp)
0