結果
| 問題 | No.1909 Detect from Substrings | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-11-06 15:13:50 | 
| 言語 | Rust (1.83.0 + proconio) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 98 ms / 2,000 ms | 
| コード長 | 1,675 bytes | 
| コンパイル時間 | 14,447 ms | 
| コンパイル使用メモリ | 377,452 KB | 
| 実行使用メモリ | 36,196 KB | 
| 最終ジャッジ日時 | 2024-07-20 04:34:43 | 
| 合計ジャッジ時間 | 17,785 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 36 | 
ソースコード
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 diff_at = (0..m).filter(|&i| words[0][i] != words[1][i]).nth(0).unwrap();
    let t1 = format!("{}{}{}",
            (0..diff_at).map(|i| words[0][i].to_string()).collect::<Vec<_>>().join(""),
            words[0][diff_at],
            (diff_at..m).map(|i| words[1][i].to_string()).collect::<Vec<_>>().join("")
        )
        .chars()
        .collect::<Vec<_>>();
    let t2 = format!("{}{}{}",
            (0..diff_at).map(|i| words[0][i].to_string()).collect::<Vec<_>>().join(""),
            words[1][diff_at],
            (diff_at..m).map(|i| words[0][i].to_string()).collect::<Vec<_>>().join("")
        )
        .chars()
        .collect::<Vec<_>>();
    let ok = |word: &Vec<char>, t: &Vec<char>| -> bool {
        let m = word.len();
        let diff_at = (0..=m).filter(|&i| i == m || word[i] != t[i]).nth(0).unwrap();
        if diff_at == m { return true; }
        (diff_at..m).map(|i| word[i] == t[i+1]).fold(true, |x, y| x && y)
    };
    let mut result = 0usize;
    if (0..n).filter(|&i| !ok(&words[i], &t1)).count() == 0 {
        result += 1;
    }
    if (0..n).filter(|&i| !ok(&words[i], &t2)).count() == 0 {
        result += 1;
    }
    println!("{}", result);
}
            
            
            
        