結果

問題 No.1909 Detect from Substrings
ユーザー phsplsphspls
提出日時 2022-10-10 19:29:33
言語 Rust
(1.77.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 1,793 bytes
コンパイル時間 1,162 ms
コンパイル使用メモリ 151,508 KB
実行使用メモリ 36,208 KB
最終ジャッジ日時 2023-09-06 21:42:19
合計ジャッジ時間 6,810 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 0 ms
4,376 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 9 ms
6,052 KB
testcase_07 AC 7 ms
6,060 KB
testcase_08 AC 87 ms
36,092 KB
testcase_09 AC 85 ms
36,100 KB
testcase_10 AC 41 ms
17,828 KB
testcase_11 AC 41 ms
17,784 KB
testcase_12 AC 25 ms
11,812 KB
testcase_13 AC 87 ms
36,120 KB
testcase_14 AC 86 ms
36,024 KB
testcase_15 AC 87 ms
36,016 KB
testcase_16 AC 25 ms
11,908 KB
testcase_17 AC 9 ms
6,340 KB
testcase_18 AC 8 ms
6,028 KB
testcase_19 AC 8 ms
6,060 KB
testcase_20 AC 8 ms
6,032 KB
testcase_21 AC 88 ms
36,028 KB
testcase_22 AC 91 ms
35,916 KB
testcase_23 AC 41 ms
17,972 KB
testcase_24 AC 41 ms
17,868 KB
testcase_25 AC 25 ms
11,924 KB
testcase_26 AC 91 ms
35,984 KB
testcase_27 AC 90 ms
36,204 KB
testcase_28 AC 89 ms
36,204 KB
testcase_29 AC 87 ms
36,164 KB
testcase_30 AC 93 ms
36,196 KB
testcase_31 AC 93 ms
35,996 KB
testcase_32 AC 90 ms
35,988 KB
testcase_33 AC 93 ms
36,024 KB
testcase_34 AC 92 ms
36,208 KB
testcase_35 AC 91 ms
36,192 KB
testcase_36 AC 89 ms
36,180 KB
testcase_37 AC 89 ms
36,200 KB
testcase_38 AC 90 ms
36,132 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().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);
}
0