結果

問題 No.1818 6 Operations
ユーザー phsplsphspls
提出日時 2022-10-27 11:21:20
言語 Rust
(1.77.0)
結果
AC  
実行時間 221 ms / 2,500 ms
コード長 1,360 bytes
コンパイル時間 1,054 ms
コンパイル使用メモリ 152,108 KB
実行使用メモリ 115,108 KB
最終ジャッジ日時 2023-09-18 05:01:45
合計ジャッジ時間 6,351 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 67 ms
35,724 KB
testcase_09 AC 127 ms
66,856 KB
testcase_10 AC 67 ms
35,996 KB
testcase_11 AC 62 ms
33,264 KB
testcase_12 AC 101 ms
53,400 KB
testcase_13 AC 83 ms
43,864 KB
testcase_14 AC 96 ms
50,508 KB
testcase_15 AC 111 ms
58,120 KB
testcase_16 AC 92 ms
48,620 KB
testcase_17 AC 137 ms
71,624 KB
testcase_18 AC 193 ms
99,572 KB
testcase_19 AC 185 ms
95,564 KB
testcase_20 AC 195 ms
101,196 KB
testcase_21 AC 198 ms
102,788 KB
testcase_22 AC 171 ms
88,520 KB
testcase_23 AC 209 ms
109,000 KB
testcase_24 AC 175 ms
91,412 KB
testcase_25 AC 221 ms
115,108 KB
testcase_26 AC 178 ms
93,276 KB
testcase_27 AC 187 ms
97,484 KB
testcase_28 AC 67 ms
35,992 KB
testcase_29 AC 62 ms
33,592 KB
testcase_30 AC 190 ms
99,364 KB
testcase_31 AC 202 ms
105,600 KB
testcase_32 AC 216 ms
110,664 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