結果

問題 No.225 文字列変更(medium)
ユーザー fmhrfmhr
提出日時 2015-06-12 22:59:50
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 875 bytes
コンパイル時間 10,550 ms
コンパイル使用メモリ 227,252 KB
実行使用メモリ 12,064 KB
最終ジャッジ日時 2024-04-19 02:22:42
合計ジャッジ時間 11,568 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 WA -
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 16 ms
9,856 KB
testcase_14 WA -
testcase_15 AC 17 ms
9,472 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 14 ms
9,344 KB
testcase_21 AC 13 ms
9,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n, m int
	var S, T string
	fmt.Scan(&n, &m, &S, &T)
	s:= strings.Split(S,"")
	t:= strings.Split(T,"")
	fmt.Println(lesvenshteinDistance(s, t))
}

func lesvenshteinDistance(str1 []string, str2 []string)int{
	d := makeDoubleSliceInt(len(str1)+1, len(str2)+1)
	for i1 :=0; i1<=len(str1);i1++{
		d[i1][0]=i1
	}
	for i2:=0; i2<=len(str2);i2++{
		d[0][i2] = i2
	}
	var cost int
	for i:=1;i<len(str1);i++{
		for j:=1;j<len(str2);j++{
			if str1[i]==str2[j]{
				cost=0
			}else{
				cost=1
			}
			d[i][j]=min(d[i-1][j]+1, min(d[i][j-1]+1, d[i-1][j-1]+cost))
		}
	}
	//fmt.Println(d)
	return d[len(str1)-1][len(str2)-1]
}

func makeDoubleSliceInt(y, x int) [][]int {
	ss := make([][]int, y)
	for i := range ss {
		ss[i] = make([]int, x)
	}
	return ss
}

func min(a, b int) int {
	if a < b {
		a, b = b, a
	}
	return b
}
0