結果

問題 No.225 文字列変更(medium)
ユーザー phsplsphspls
提出日時 2020-02-15 15:46:30
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,257 bytes
コンパイル時間 5,299 ms
コンパイル使用メモリ 157,064 KB
実行使用メモリ 9,344 KB
最終ジャッジ日時 2024-04-16 03:13:19
合計ジャッジ時間 1,816 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
5,248 KB
testcase_01 AC 8 ms
6,912 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 WA -
testcase_06 AC 1 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 0 ms
5,376 KB
testcase_12 AC 10 ms
8,832 KB
testcase_13 WA -
testcase_14 AC 11 ms
9,216 KB
testcase_15 AC 10 ms
8,832 KB
testcase_16 AC 10 ms
8,960 KB
testcase_17 AC 10 ms
8,832 KB
testcase_18 AC 11 ms
8,704 KB
testcase_19 AC 10 ms
8,960 KB
testcase_20 WA -
testcase_21 AC 11 ms
8,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp::min;

fn main() {
    let mut nm: String = String::new();
    std::io::stdin().read_line(&mut nm).ok();
    let nm: Vec<usize> = nm.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let mut s: String = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let s: Vec<char> = s.trim().chars().collect();
    let mut t: String = String::new();
    std::io::stdin().read_line(&mut t).ok();
    let t: Vec<char> = t.trim().chars().collect();

    let n: usize = nm[0];
    let m: usize = nm[1];

    const LIMIT: usize = 2000;
    let mut dp: Vec<Vec<usize>> = vec![vec![LIMIT; m+1]; n+1];
    dp[0][0] = 0;
    for i in 0..n {
        let s_char = s[i];
        for j in 0..m {
            let t_char = t[j];
            /*
            del: sから現在見ている1文字を削除 = sのindexを1すすめる
            ins: tで現在見ている1文字と同じ文字をsに追加する = tのindexを1すすめる
            */
            if s_char == t_char {
                dp[i+1][j+1] = min(min(dp[i][j], dp[i+1][j] + 1), dp[i][j+1]+1);
            } else {
                dp[i+1][j+1] = min(min(dp[i][j] + 1, dp[i+1][j] + 1), dp[i][j+1]+1);
            }
        }
    }
    println!("{}", dp[n][m]);
}
0