結果

問題 No.1909 Detect from Substrings
ユーザー phsplsphspls
提出日時 2022-10-23 12:35:30
言語 Rust
(1.77.0)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 1,789 bytes
コンパイル時間 1,220 ms
コンパイル使用メモリ 151,872 KB
実行使用メモリ 36,212 KB
最終ジャッジ日時 2023-09-14 23:36:08
合計ジャッジ時間 6,916 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 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 4 ms
4,380 KB
testcase_06 AC 7 ms
6,012 KB
testcase_07 AC 7 ms
6,120 KB
testcase_08 AC 92 ms
36,172 KB
testcase_09 AC 92 ms
36,052 KB
testcase_10 AC 42 ms
17,880 KB
testcase_11 AC 42 ms
17,856 KB
testcase_12 AC 25 ms
11,912 KB
testcase_13 AC 94 ms
36,212 KB
testcase_14 AC 94 ms
36,052 KB
testcase_15 AC 93 ms
35,972 KB
testcase_16 AC 25 ms
11,892 KB
testcase_17 AC 8 ms
6,344 KB
testcase_18 AC 7 ms
6,008 KB
testcase_19 AC 7 ms
6,080 KB
testcase_20 AC 7 ms
6,168 KB
testcase_21 AC 95 ms
35,952 KB
testcase_22 AC 94 ms
35,968 KB
testcase_23 AC 41 ms
17,944 KB
testcase_24 AC 42 ms
17,868 KB
testcase_25 AC 24 ms
11,908 KB
testcase_26 AC 93 ms
35,940 KB
testcase_27 AC 95 ms
36,212 KB
testcase_28 AC 94 ms
36,128 KB
testcase_29 AC 96 ms
36,136 KB
testcase_30 AC 93 ms
36,096 KB
testcase_31 AC 95 ms
36,004 KB
testcase_32 AC 94 ms
36,060 KB
testcase_33 AC 94 ms
35,960 KB
testcase_34 AC 94 ms
36,148 KB
testcase_35 AC 96 ms
36,188 KB
testcase_36 AC 98 ms
36,212 KB
testcase_37 AC 95 ms
36,208 KB
testcase_38 AC 95 ms
36,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn is_ok(s: &Vec<char>, t: &Vec<char>) -> bool {
    let m = s.len();
    let diff_point = (0..=m).filter(|&i| if i == m { true } else { s[i] != t[i] }).nth(0).unwrap();
    !(diff_point..m).any(|i| s[i] != t[i+1])
}

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 same_s = (0..m).filter(|&i| s1[i] != s2[i]).nth(0).unwrap();
    let same_e = (0..m).rev().filter(|&i| s1[i] != s2[i]).nth(0).unwrap()+1;
    let t1 = format!("{}{}{}{}",
        (0..same_s).map(|i| s1[i].to_string()).collect::<Vec<_>>().join(""),
        (same_s..same_e).map(|i| s1[i].to_string()).collect::<Vec<_>>().join(""),
        s2[same_e-1],
        (same_e..m).map(|i| s1[i].to_string()).collect::<Vec<_>>().join("")
    )
    .chars().collect::<Vec<_>>();
    let t2 = format!("{}{}{}{}",
        (0..same_s).map(|i| s1[i].to_string()).collect::<Vec<_>>().join(""),
        (same_s..same_e).map(|i| s2[i].to_string()).collect::<Vec<_>>().join(""),
        s1[same_e-1],
        (same_e..m).map(|i| s1[i].to_string()).collect::<Vec<_>>().join("")
    )
    .chars().collect::<Vec<_>>();

    let mut result = 0usize;
    if (0..n).filter(|&i| is_ok(&words[i], &t1)).count() == n {
        result += 1;
    }
    if (0..n).filter(|&i| is_ok(&words[i], &t2)).count() == n {
        result += 1;
    }
    println!("{}", result);
}
0