結果

問題 No.1818 6 Operations
ユーザー phsplsphspls
提出日時 2022-10-20 10:40:00
言語 Rust
(1.77.0)
結果
AC  
実行時間 220 ms / 2,500 ms
コード長 1,360 bytes
コンパイル時間 3,573 ms
コンパイル使用メモリ 145,220 KB
実行使用メモリ 115,048 KB
最終ジャッジ日時 2023-09-12 16:55:03
合計ジャッジ時間 7,702 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 0 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 67 ms
35,696 KB
testcase_09 AC 127 ms
66,864 KB
testcase_10 AC 67 ms
35,976 KB
testcase_11 AC 61 ms
33,332 KB
testcase_12 AC 100 ms
53,384 KB
testcase_13 AC 83 ms
43,828 KB
testcase_14 AC 95 ms
50,428 KB
testcase_15 AC 109 ms
58,152 KB
testcase_16 AC 92 ms
48,636 KB
testcase_17 AC 135 ms
71,340 KB
testcase_18 AC 190 ms
99,596 KB
testcase_19 AC 182 ms
95,636 KB
testcase_20 AC 192 ms
101,120 KB
testcase_21 AC 195 ms
102,704 KB
testcase_22 AC 167 ms
88,480 KB
testcase_23 AC 207 ms
109,040 KB
testcase_24 AC 174 ms
91,408 KB
testcase_25 AC 220 ms
115,048 KB
testcase_26 AC 176 ms
93,256 KB
testcase_27 AC 188 ms
97,404 KB
testcase_28 AC 65 ms
35,968 KB
testcase_29 AC 61 ms
33,596 KB
testcase_30 AC 189 ms
99,324 KB
testcase_31 AC 202 ms
105,676 KB
testcase_32 AC 209 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.into_iter().flat_map(|v| { let mut ret = vec![1usize; v+1]; ret[0] = 0; ret }).collect::<Vec<_>>();
    let b = b.into_iter().flat_map(|v| { let mut ret = vec![1usize; v+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