結果

問題 No.430 文字列検索
ユーザー hatoohatoo
提出日時 2019-05-15 23:56:10
言語 Rust
(1.77.0 + proconio)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 4,711 bytes
コンパイル時間 12,049 ms
コンパイル使用メモリ 403,004 KB
実行使用メモリ 34,888 KB
最終ジャッジ日時 2024-11-10 00:25:31
合計ジャッジ時間 13,430 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 111 ms
34,888 KB
testcase_02 AC 24 ms
6,820 KB
testcase_03 AC 25 ms
6,816 KB
testcase_04 AC 1 ms
6,820 KB
testcase_05 AC 0 ms
6,816 KB
testcase_06 AC 1 ms
6,820 KB
testcase_07 AC 1 ms
6,820 KB
testcase_08 AC 114 ms
34,648 KB
testcase_09 AC 1 ms
6,816 KB
testcase_10 AC 10 ms
6,820 KB
testcase_11 AC 41 ms
10,548 KB
testcase_12 AC 41 ms
10,548 KB
testcase_13 AC 42 ms
10,416 KB
testcase_14 AC 33 ms
6,820 KB
testcase_15 AC 30 ms
6,820 KB
testcase_16 AC 24 ms
6,820 KB
testcase_17 AC 24 ms
6,816 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