結果
| 問題 | No.1909 Detect from Substrings | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-10-09 23:39:09 | 
| 言語 | Rust (1.83.0 + proconio) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,831 bytes | 
| コンパイル時間 | 13,703 ms | 
| コンパイル使用メモリ | 400,688 KB | 
| 実行使用メモリ | 36,220 KB | 
| 最終ジャッジ日時 | 2024-06-23 21:06:57 | 
| 合計ジャッジ時間 | 18,162 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 17 WA * 19 | 
コンパイルメッセージ
warning: unused import: `std::fmt::format` --> src/main.rs:1:5 | 1 | use std::fmt::format; | ^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default
ソースコード
use std::fmt::format;
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 a = &words[0];
    let b = &words[1];
    let start = (0..m).filter(|&i| a[i] != b[i]).nth(0).unwrap();
    let end = (0..m).rev().filter(|&i| a[i] != b[i]).nth(0).unwrap();
    let t1 = format!("{}{}{}{}"
        , (0..start).map(|i| a[i].to_string()).collect::<Vec<_>>().join("")
        , (start..=end).map(|i| a[i].to_string()).collect::<Vec<_>>().join("")
        , b[end]
        , (end+1..m).map(|i| a[i].to_string()).collect::<Vec<_>>().join(""))
        .chars().collect::<Vec<_>>();
    let t2 = format!("{}{}{}{}"
        , (0..start).map(|i| a[i].to_string()).collect::<Vec<_>>().join("")
        , (start..=end).map(|i| b[i].to_string()).collect::<Vec<_>>().join("")
        , a[end]
        , (end+1..m).map(|i| a[i].to_string()).collect::<Vec<_>>().join(""))
        .chars().collect::<Vec<_>>();
    let mut result = 0usize;
    let word_ok = |i: usize, t: &Vec<char>| {
        let start = (0..m+1).filter(|&j| j == m || words[i][j] != t[j]).nth(0).unwrap();
        let end = m - (0..m+1).rev().filter(|&j| j == 0 || words[i][j-1] != t[j]).nth(0).unwrap();
        start + end == m
    };
    let temp = (0..n).filter(|&i| word_ok(i, &t1)).count() == n;
    if temp { result += 1; }
    let temp = (0..n).filter(|&i| word_ok(i, &t2)).count() == n;
    if temp { result += 1; }
    println!("{}", result);
}
            
            
            
        