結果

問題 No.430 文字列検索
ユーザー akakimidoriakakimidori
提出日時 2019-08-13 05:43:33
言語 Rust
(1.77.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 882 bytes
コンパイル時間 1,854 ms
コンパイル使用メモリ 185,280 KB
実行使用メモリ 21,352 KB
最終ジャッジ日時 2023-10-19 10:07:13
合計ジャッジ時間 2,626 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 71 ms
21,352 KB
testcase_02 AC 17 ms
4,348 KB
testcase_03 AC 17 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 71 ms
21,352 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 8 ms
4,496 KB
testcase_11 AC 35 ms
6,928 KB
testcase_12 AC 34 ms
6,928 KB
testcase_13 AC 34 ms
6,928 KB
testcase_14 AC 28 ms
4,544 KB
testcase_15 AC 23 ms
4,348 KB
testcase_16 AC 17 ms
4,348 KB
testcase_17 AC 17 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::BufRead;

fn run() {
    let stdin = std::io::stdin();
    let mut stdin = stdin.lock();
    let mut s = String::new();
    stdin.read_line(&mut s).unwrap();
    let s = s.trim();
    let mut map = std::collections::HashMap::new();
    for i in 0..s.len() {
        for j in 1..(std::cmp::min(11, s.len() + 1 - i)) {
            let s = &s[i..(i + j)];
            let po = map.entry(s).or_insert(0);
            *po += 1;
        }
    }
    let mut ans = 0;
    let mut s = String::new();
    stdin.read_line(&mut s).unwrap();
    let m: usize = s.split_whitespace().next().unwrap().parse().ok().unwrap();
    for _ in 0..m {
        s.clear();
        stdin.read_line(&mut s).unwrap();
        let s = s.trim();
        match map.get(s) {
            Some(&c) => ans += c,
            None => (),
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}
0