結果

問題 No.1818 6 Operations
ユーザー phsplsphspls
提出日時 2022-10-14 22:22:28
言語 Rust
(1.77.0)
結果
AC  
実行時間 219 ms / 2,500 ms
コード長 1,458 bytes
コンパイル時間 6,021 ms
コンパイル使用メモリ 148,568 KB
実行使用メモリ 115,136 KB
最終ジャッジ日時 2023-09-08 22:23:24
合計ジャッジ時間 8,524 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 68 ms
35,680 KB
testcase_09 AC 126 ms
66,876 KB
testcase_10 AC 67 ms
35,916 KB
testcase_11 AC 62 ms
33,352 KB
testcase_12 AC 101 ms
53,400 KB
testcase_13 AC 82 ms
43,864 KB
testcase_14 AC 95 ms
50,460 KB
testcase_15 AC 110 ms
58,140 KB
testcase_16 AC 93 ms
48,656 KB
testcase_17 AC 139 ms
71,620 KB
testcase_18 AC 190 ms
99,568 KB
testcase_19 AC 182 ms
95,600 KB
testcase_20 AC 192 ms
101,132 KB
testcase_21 AC 197 ms
102,780 KB
testcase_22 AC 167 ms
88,528 KB
testcase_23 AC 206 ms
109,048 KB
testcase_24 AC 173 ms
91,420 KB
testcase_25 AC 219 ms
115,136 KB
testcase_26 AC 177 ms
93,272 KB
testcase_27 AC 184 ms
97,448 KB
testcase_28 AC 66 ms
35,952 KB
testcase_29 AC 62 ms
33,584 KB
testcase_30 AC 193 ms
99,304 KB
testcase_31 AC 202 ms
105,536 KB
testcase_32 AC 209 ms
110,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

const INF: usize = 1usize << 60;

fn main() {
    let mut nm = 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 n = nm[0];
    let m = nm[1];
    let mut a = String::new();
    std::io::stdin().read_line(&mut a).ok();
    let a: Vec<usize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let mut b = String::new();
    std::io::stdin().read_line(&mut b).ok();
    let b: Vec<usize> = b.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let a = (0..n).flat_map(|i| {
            let mut ret = vec![1usize; a[i]+1];
            ret[0] = 0;
            ret
        })
        .collect::<Vec<_>>();
    let b = (0..m).flat_map(|i| {
            let mut ret = vec![1usize; b[i]+1];
            ret[0] = 0;
            ret
        })
        .collect::<Vec<_>>();
    let n = a.len();
    let m = b.len();
    let mut dp = vec![vec![INF; m+1]; n+1];
    dp[0][0] = 0;
    for i in 0..=n {
        for j in 0..=m {
            if i+1 <= n {
                dp[i+1][j] = dp[i+1][j].min(dp[i][j] + 1);
            }
            if j+1 <= m {
                dp[i][j+1] = dp[i][j+1].min(dp[i][j] + 1);
            }
            if i+1 <= n && j+1 <= m {
                dp[i+1][j+1] = dp[i+1][j+1].min(dp[i][j] + if a[i] == b[j] { 0 } else { 1 });
            }
        }
    }
    println!("{}", dp[n][m]);
}
0