結果

問題 No.1818 6 Operations
ユーザー phsplsphspls
提出日時 2022-11-10 11:07:57
言語 Rust
(1.77.0)
結果
AC  
実行時間 188 ms / 2,500 ms
コード長 1,360 bytes
コンパイル時間 1,683 ms
コンパイル使用メモリ 153,300 KB
実行使用メモリ 115,204 KB
最終ジャッジ日時 2023-09-30 20:06:33
合計ジャッジ時間 6,528 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 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,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 56 ms
35,696 KB
testcase_09 AC 107 ms
66,884 KB
testcase_10 AC 58 ms
35,964 KB
testcase_11 AC 53 ms
33,348 KB
testcase_12 AC 86 ms
53,352 KB
testcase_13 AC 70 ms
43,912 KB
testcase_14 AC 81 ms
50,508 KB
testcase_15 AC 94 ms
58,148 KB
testcase_16 AC 79 ms
48,316 KB
testcase_17 AC 116 ms
71,316 KB
testcase_18 AC 164 ms
99,616 KB
testcase_19 AC 155 ms
95,648 KB
testcase_20 AC 165 ms
101,204 KB
testcase_21 AC 169 ms
102,772 KB
testcase_22 AC 143 ms
88,524 KB
testcase_23 AC 178 ms
108,860 KB
testcase_24 AC 148 ms
91,428 KB
testcase_25 AC 188 ms
115,204 KB
testcase_26 AC 150 ms
93,276 KB
testcase_27 AC 159 ms
97,516 KB
testcase_28 AC 58 ms
35,980 KB
testcase_29 AC 53 ms
33,624 KB
testcase_30 AC 163 ms
99,304 KB
testcase_31 AC 173 ms
105,680 KB
testcase_32 AC 180 ms
110,700 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![1; a[i]+1]; ret[0] = 0; ret }).collect::<Vec<_>>();
    let b = (0..m).flat_map(|i| { let mut ret = vec![1; b[i]+1]; ret[0] = 0; ret }).collect::<Vec<_>>();
    let mut dp = vec![vec![INF; b.len()+1]; a.len()+1];
    dp[0][0] = 0;
    for i in 0..=a.len() {
        for j in 0..=b.len() {
            if i+1 <= a.len() {
                dp[i+1][j] = dp[i+1][j].min(dp[i][j] + 1);
            }
            if j+1 <= b.len() {
                dp[i][j+1] = dp[i][j+1].min(dp[i][j] + 1);
            }
            if i+1 <= a.len() && j+1 <= b.len() {
                dp[i+1][j+1] = dp[i+1][j+1].min(dp[i][j] + if a[i] == b[j] { 0 } else { 1 });
            }
        }
    }
    println!("{}", dp[a.len()][b.len()]);
}
0