結果

問題 No.1909 Detect from Substrings
ユーザー phsplsphspls
提出日時 2022-10-16 13:58:11
言語 Rust
(1.77.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 1,874 bytes
コンパイル時間 2,262 ms
コンパイル使用メモリ 154,124 KB
実行使用メモリ 36,220 KB
最終ジャッジ日時 2023-09-09 17:09:15
合計ジャッジ時間 8,908 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 5 ms
4,380 KB
testcase_06 AC 9 ms
6,080 KB
testcase_07 AC 9 ms
6,104 KB
testcase_08 AC 98 ms
36,104 KB
testcase_09 AC 97 ms
36,092 KB
testcase_10 AC 47 ms
17,828 KB
testcase_11 AC 45 ms
17,864 KB
testcase_12 AC 28 ms
11,812 KB
testcase_13 AC 98 ms
36,220 KB
testcase_14 AC 99 ms
36,024 KB
testcase_15 AC 101 ms
36,000 KB
testcase_16 AC 28 ms
11,868 KB
testcase_17 AC 10 ms
6,284 KB
testcase_18 AC 10 ms
6,108 KB
testcase_19 AC 10 ms
6,024 KB
testcase_20 AC 9 ms
6,104 KB
testcase_21 AC 100 ms
35,968 KB
testcase_22 AC 100 ms
36,008 KB
testcase_23 AC 47 ms
17,916 KB
testcase_24 AC 45 ms
17,864 KB
testcase_25 AC 28 ms
11,924 KB
testcase_26 AC 100 ms
35,896 KB
testcase_27 AC 99 ms
36,216 KB
testcase_28 AC 100 ms
36,140 KB
testcase_29 AC 101 ms
36,100 KB
testcase_30 AC 94 ms
36,136 KB
testcase_31 AC 94 ms
35,988 KB
testcase_32 AC 95 ms
36,048 KB
testcase_33 AC 94 ms
36,036 KB
testcase_34 AC 95 ms
36,196 KB
testcase_35 AC 94 ms
36,152 KB
testcase_36 AC 97 ms
36,148 KB
testcase_37 AC 97 ms
36,220 KB
testcase_38 AC 96 ms
36,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 words = (0..n).map(|_| {
            let mut temp = String::new();
            std::io::stdin().read_line(&mut temp).ok();
            let temp = temp.trim();
            temp.chars().collect::<Vec<_>>()
        })
        .collect::<Vec<_>>();

    let s1 = &words[0];
    let s2 = &words[1];
    let front_same_cnt = (0..m).filter(|&i| s1[i] != s2[i]).nth(0).unwrap();
    let back_diff_point = (0..m).rev().filter(|&i| s1[i] != s2[i]).nth(0).unwrap();
    let t1 = format!("{}{}{}{}",
        (0..front_same_cnt).map(|i| s1[i].to_string()).collect::<Vec<_>>().join(""),
        (front_same_cnt..=back_diff_point).map(|i| s1[i].to_string()).collect::<Vec<_>>().join(""),
        s2[back_diff_point],
        (back_diff_point+1..m).map(|i| s1[i].to_string()).collect::<Vec<_>>().join("")
    ).chars().collect::<Vec<_>>();
    let t2 = format!("{}{}{}{}",
        (0..front_same_cnt).map(|i| s2[i].to_string()).collect::<Vec<_>>().join(""),
        (front_same_cnt..=back_diff_point).map(|i| s2[i].to_string()).collect::<Vec<_>>().join(""),
        s1[back_diff_point],
        (back_diff_point+1..m).map(|i| s2[i].to_string()).collect::<Vec<_>>().join("")
    ).chars().collect::<Vec<_>>();
    let is_ok = |s: &Vec<char>, t: &Vec<char>| {
        let front_same_cnt = (0..m+1).filter(|&i| i == m || s[i] != t[i]).nth(0).unwrap();
        (front_same_cnt..s.len()).filter(|&i| s[i] != t[i+1]).count() == 0
    };
    let mut result = 0;
    if (0..n).map(|i| is_ok(&words[i], &t1)).fold(true, |x, y| x && y) { result += 1; }
    if (0..n).map(|i| is_ok(&words[i], &t2)).fold(true, |x, y| x && y) { result += 1; }
    println!("{}", result);
}
0