結果

問題 No.430 文字列検索
ユーザー hatoohatoo
提出日時 2019-05-15 23:56:10
言語 Rust
(1.77.0)
結果
AC  
実行時間 171 ms / 2,000 ms
コード長 4,711 bytes
コンパイル時間 2,337 ms
コンパイル使用メモリ 164,520 KB
実行使用メモリ 33,892 KB
最終ジャッジ日時 2023-10-12 18:55:19
合計ジャッジ時間 3,665 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 171 ms
33,892 KB
testcase_02 AC 31 ms
4,480 KB
testcase_03 AC 31 ms
4,348 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 138 ms
33,620 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 11 ms
5,020 KB
testcase_11 AC 52 ms
9,500 KB
testcase_12 AC 52 ms
9,584 KB
testcase_13 AC 52 ms
9,504 KB
testcase_14 AC 43 ms
5,424 KB
testcase_15 AC 38 ms
4,356 KB
testcase_16 AC 31 ms
4,352 KB
testcase_17 AC 32 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[doc = " https://github.com/hatoo/competitive-rust-snippets"]
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
mod util {
    use std::fmt::Debug;
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( [ $ t : ty ] ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( [ $ t : ty ] ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( [ $ t ] ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

use std::default::Default;
use std::hash::{BuildHasherDefault, Hasher};
#[doc = " An implementation of the Fowler\u{2013}Noll\u{2013}Vo hash function."]
#[doc = ""]
#[doc = " See the [crate documentation](index.html) for more details."]
#[doc = " Ported from [servo/rust-fnv](https://raw.githubusercontent.com/servo/rust-fnv/master/lib.rs)"]
#[allow(missing_copy_implementations)]
pub struct FnvHasher(u64);
impl Default for FnvHasher {
    #[inline]
    fn default() -> FnvHasher {
        FnvHasher(0xcbf29ce484222325)
    }
}
impl FnvHasher {
    #[doc = " Create an FNV hasher starting with a state corresponding"]
    #[doc = " to the hash `key`."]
    #[inline]
    pub fn with_key(key: u64) -> FnvHasher {
        FnvHasher(key)
    }
}
impl Hasher for FnvHasher {
    #[inline]
    fn finish(&self) -> u64 {
        self.0
    }
    #[inline]
    fn write(&mut self, bytes: &[u8]) {
        let FnvHasher(mut hash) = *self;
        for byte in bytes.iter() {
            hash = hash ^ (*byte as u64);
            hash = hash.wrapping_mul(0x100000001b3);
        }
        *self = FnvHasher(hash);
    }
}
#[doc = " A builder for default FNV hashers."]
pub type FnvBuildHasher = BuildHasherDefault<FnvHasher>;
#[doc = " A `HashMap` using a default FNV hasher."]
pub type FnvHashMap<K, V> = HashMap<K, V, FnvBuildHasher>;
#[doc = " A `HashSet` using a default FNV hasher."]
pub type FnvHashSet<T> = HashSet<T, FnvBuildHasher>;

fn solve() {
    let s = util::chars();
    let m = get!(usize);
    let c = get!(String; m);

    let mut map: FnvHashMap<String, usize> = Default::default();

    for i in 1..=10 {
        for w in s.windows(i) {
            *map.entry(w.iter().collect::<String>()).or_default() += 1;
        }
    }

    let ans = c
        .into_iter()
        .map(|s| map.get(&s).unwrap_or(&0))
        .sum::<usize>();

    println!("{}", ans);
}
0