結果
| 問題 | No.1909 Detect from Substrings | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-10-10 19:29:33 | 
| 言語 | Rust (1.83.0 + proconio) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 99 ms / 2,000 ms | 
| コード長 | 1,793 bytes | 
| コンパイル時間 | 14,220 ms | 
| コンパイル使用メモリ | 384,136 KB | 
| 実行使用メモリ | 36,248 KB | 
| 最終ジャッジ日時 | 2024-06-24 16:00:11 | 
| 合計ジャッジ時間 | 18,962 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| 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().chars().collect::<Vec<_>>();
            temp
        })
        .collect::<Vec<_>>();
    let s1 = &words[0];
    let s2 = &words[1];
    let start = (0..m).filter(|&i| s1[i] != s2[i]).nth(0).unwrap();
    let end = (0..m).rev().filter(|&i| s1[i] != s2[i]).nth(0).unwrap();
    let t1 = format!("{}{}{}{}",
              (0..start).map(|i| s1[i].to_string()).collect::<Vec<_>>().join("")
            , (start..=end).map(|i| s1[i].to_string()).collect::<Vec<_>>().join("")
            , s2[end]
            , (end+1..m).map(|i| s1[i].to_string()).collect::<Vec<_>>().join("")
        )
        .chars()
        .collect::<Vec<_>>();
    let t2 = format!("{}{}{}{}",
              (0..start).map(|i| s2[i].to_string()).collect::<Vec<_>>().join("")
            , (start..=end).map(|i| s2[i].to_string()).collect::<Vec<_>>().join("")
            , s1[end]
            , (end+1..m).map(|i| s2[i].to_string()).collect::<Vec<_>>().join("")
        )
        .chars()
        .collect::<Vec<_>>();
    let mut result = 0usize;
    let ok = |t: &Vec<char>| {
        (0..n).map(|i| {
                let start = (0..m+1).filter(|&j| if j == m { true } else { words[i][j] != t[j] }).nth(0).unwrap();
                !(start..m).any(|j| words[i][j] != t[j+1])
            })
            .fold(true, |x, y| x && y)
    };
    if ok(&t1) { result += 1; }
    if ok(&t2) { result += 1; }
    println!("{}", result);
}
            
            
            
        