結果
問題 | No.225 文字列変更(medium) |
ユーザー | aru aru |
提出日時 | 2020-09-19 12:02:14 |
言語 | Go (1.22.1) |
結果 |
AC
|
実行時間 | 31 ms / 5,000 ms |
コード長 | 1,616 bytes |
コンパイル時間 | 13,073 ms |
コンパイル使用メモリ | 209,420 KB |
実行使用メモリ | 11,428 KB |
最終ジャッジ日時 | 2023-09-05 14:34:25 |
合計ジャッジ時間 | 14,419 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 14 ms
11,424 KB |
testcase_01 | AC | 24 ms
11,428 KB |
testcase_02 | AC | 5 ms
11,416 KB |
testcase_03 | AC | 5 ms
11,416 KB |
testcase_04 | AC | 5 ms
11,420 KB |
testcase_05 | AC | 5 ms
11,416 KB |
testcase_06 | AC | 5 ms
11,420 KB |
testcase_07 | AC | 5 ms
11,420 KB |
testcase_08 | AC | 4 ms
11,416 KB |
testcase_09 | AC | 5 ms
11,416 KB |
testcase_10 | AC | 5 ms
11,416 KB |
testcase_11 | AC | 5 ms
11,420 KB |
testcase_12 | AC | 29 ms
11,424 KB |
testcase_13 | AC | 31 ms
11,424 KB |
testcase_14 | AC | 30 ms
11,424 KB |
testcase_15 | AC | 29 ms
11,420 KB |
testcase_16 | AC | 30 ms
11,420 KB |
testcase_17 | AC | 30 ms
11,420 KB |
testcase_18 | AC | 29 ms
11,420 KB |
testcase_19 | AC | 30 ms
11,420 KB |
testcase_20 | AC | 28 ms
11,420 KB |
testcase_21 | AC | 30 ms
11,424 KB |
ソースコード
package main import ( "bufio" "fmt" "os" "sort" "strconv" ) func out(x ...interface{}) { fmt.Println(x...) } var sc = bufio.NewScanner(os.Stdin) func getInt() int { sc.Scan() i, e := strconv.Atoi(sc.Text()) if e != nil { panic(e) } return i } func getInts(N int) []int { ret := make([]int, N) for i := 0; i < N; i++ { ret[i] = getInt() } return ret } func getString() string { sc.Scan() return sc.Text() } // min, max, asub, absなど基本関数 func max(a, b int) int { if a > b { return a } return b } func min(a, b int) int { if a < b { return a } return b } func asub(a, b int) int { if a > b { return a - b } return b - a } func abs(a int) int { if a >= 0 { return a } return -a } func lowerBound(a []int, x int) int { idx := sort.Search(len(a), func(i int) bool { return a[i] >= x }) return idx } func upperBound(a []int, x int) int { idx := sort.Search(len(a), func(i int) bool { return a[i] > x }) return idx } const inf = int(1e10) var memo [1010][1010]int func rec(s, t string) int { if len(s) == 0 { return len(t) } if len(t) == 0 { return len(s) } if memo[len(s)][len(t)] != -1 { return memo[len(s)][len(t)] } cost := 1 if s[0] == t[0] { cost = 0 } l0 := rec(s[1:], t[1:]) + cost l1 := rec(s, t[1:]) + 1 l2 := rec(s[1:], t) + 1 l := min(l0, min(l1, l2)) memo[len(s)][len(t)] = l return l } var n, m int func main() { sc.Split(bufio.ScanWords) n, m = getInt(), getInt() s, t := getString(), getString() for i := 0; i < 1010; i++ { for j := 0; j < 1010; j++ { memo[i][j] = -1 } } out(rec(s, t)) }