結果

問題 No.1818 6 Operations
ユーザー phsplsphspls
提出日時 2022-10-14 01:24:33
言語 Rust
(1.77.0)
結果
AC  
実行時間 214 ms / 2,500 ms
コード長 1,468 bytes
コンパイル時間 2,262 ms
コンパイル使用メモリ 149,772 KB
実行使用メモリ 115,148 KB
最終ジャッジ日時 2023-09-08 19:21:25
合計ジャッジ時間 7,672 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 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,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 66 ms
35,716 KB
testcase_09 AC 126 ms
66,868 KB
testcase_10 AC 67 ms
35,980 KB
testcase_11 AC 61 ms
33,332 KB
testcase_12 AC 99 ms
53,360 KB
testcase_13 AC 81 ms
44,156 KB
testcase_14 AC 96 ms
50,484 KB
testcase_15 AC 107 ms
58,072 KB
testcase_16 AC 90 ms
48,636 KB
testcase_17 AC 133 ms
71,588 KB
testcase_18 AC 191 ms
99,564 KB
testcase_19 AC 181 ms
95,628 KB
testcase_20 AC 190 ms
101,172 KB
testcase_21 AC 195 ms
102,768 KB
testcase_22 AC 164 ms
88,484 KB
testcase_23 AC 206 ms
108,996 KB
testcase_24 AC 170 ms
91,404 KB
testcase_25 AC 214 ms
115,148 KB
testcase_26 AC 172 ms
93,260 KB
testcase_27 AC 179 ms
97,480 KB
testcase_28 AC 65 ms
35,988 KB
testcase_29 AC 61 ms
33,592 KB
testcase_30 AC 182 ms
99,284 KB
testcase_31 AC 197 ms
105,508 KB
testcase_32 AC 208 ms
110,676 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `n`
 --> Main.rs:8:9
  |
8 |     let n = nm[0];
  |         ^ help: if this is intentional, prefix it with an underscore: `_n`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: unused variable: `m`
 --> Main.rs:9:9
  |
9 |     let m = nm[1];
  |         ^ help: if this is intentional, prefix it with an underscore: `_m`

warning: 2 warnings emitted

ソースコード

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 = a.iter().flat_map(|&v| { 
            let mut ret = vec![1usize; v+1];
            ret[0] = 0;
            ret
        })
        .collect::<Vec<usize>>();
    let b = b.iter().flat_map(|&v| { 
            let mut ret = vec![1usize; v+1];
            ret[0] = 0;
            ret
        })
        .collect::<Vec<usize>>();
    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