結果

問題 No.871 かえるのうた
ユーザー Masaki KitaguchiMasaki Kitaguchi
提出日時 2022-02-08 00:30:13
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 1,713 bytes
コンパイル時間 3,399 ms
コンパイル使用メモリ 155,484 KB
実行使用メモリ 7,584 KB
最終ジャッジ日時 2023-09-04 19:07:40
合計ジャッジ時間 10,512 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 34 ms
4,380 KB
testcase_13 AC 6 ms
4,380 KB
testcase_14 AC 24 ms
7,528 KB
testcase_15 AC 40 ms
7,584 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#[macro_export]
macro_rules! setup {
    { mut $input:ident: SplitWhitespace $(,)? } => {
        use std::io::Read;
        let mut buf = String::new();
        std::io::stdin().read_to_string(&mut buf).ok();
        let mut $input = buf.split_whitespace();
    };
}

#[macro_export]
macro_rules! parse_next {
    ($str_iter:expr) => {
        $str_iter.next().unwrap().parse().ok().unwrap()
    };
}

#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};

fn main() {
    setup! { mut input: SplitWhitespace };

    let n: usize = parse_next!(input);
    let k: usize = parse_next!(input);
    let x: Vec<i64> = (0..n).map(|_| parse_next!(input)).collect();
    let a: Vec<i64> = (0..n).map(|_| parse_next!(input)).collect();

    let ans = (|| {
        let mut queue = VecDeque::new();
        let mut visited = HashSet::new();
        {
            let root = k - 1;
            queue.push_back(root);
            visited.insert(root);
        }
        while !queue.is_empty() {
            let i = queue.pop_front().unwrap();
            let children = x
                .iter()
                .enumerate()
                .filter(|(_, x_j)| {
                    if (x[i] - a[i] <= **x_j) && (**x_j <= x[i] + a[i]) {
                        return true;
                    }
                    false
                })
                .map(|(j, _)| j)
                .collect::<Vec<_>>();
            for j in children.into_iter() {
                if visited.contains(&j) {
                    continue;
                }
                queue.push_back(j);
                visited.insert(j);
            }
        }
        visited.len()
    })();

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