結果
問題 | No.430 文字列検索 |
ユーザー | hatoo |
提出日時 | 2019-05-16 00:00:09 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 27 ms / 2,000 ms |
コード長 | 4,671 bytes |
コンパイル時間 | 13,991 ms |
コンパイル使用メモリ | 380,012 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-10 00:25:46 |
合計ジャッジ時間 | 15,104 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 27 ms
5,248 KB |
testcase_02 | AC | 25 ms
5,248 KB |
testcase_03 | AC | 25 ms
5,248 KB |
testcase_04 | AC | 1 ms
5,248 KB |
testcase_05 | AC | 1 ms
5,248 KB |
testcase_06 | AC | 1 ms
5,248 KB |
testcase_07 | AC | 1 ms
5,248 KB |
testcase_08 | AC | 24 ms
5,248 KB |
testcase_09 | AC | 1 ms
5,248 KB |
testcase_10 | AC | 3 ms
5,248 KB |
testcase_11 | AC | 26 ms
5,248 KB |
testcase_12 | AC | 26 ms
5,248 KB |
testcase_13 | AC | 26 ms
5,248 KB |
testcase_14 | AC | 26 ms
5,248 KB |
testcase_15 | AC | 27 ms
5,248 KB |
testcase_16 | AC | 25 ms
5,248 KB |
testcase_17 | AC | 25 ms
5,248 KB |
ソースコード
#[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 set: FnvHashSet<String> = c.into_iter().collect(); let mut ans = 0; for i in 1..=10 { for w in s.windows(i) { let s = w.iter().collect::<String>(); if set.contains(&s) { ans += 1; } } } println!("{}", ans); }